{"id":786,"date":"2018-10-10T11:08:54","date_gmt":"2018-10-10T15:08:54","guid":{"rendered":"https:\/\/folvera.commons.gc.cuny.edu\/?p=786"},"modified":"2021-09-16T14:57:36","modified_gmt":"2021-09-16T18:57:36","slug":"resources-to-learn-programming-5-pep-8","status":"publish","type":"post","link":"https:\/\/folvera.commons.gc.cuny.edu\/?p=786","title":{"rendered":"Resources to Learn Programming #5 (PEP 8)"},"content":{"rendered":"<p>The following is true for <a title=\"Python\" href=\"https:\/\/www.python.org\/\" target=\"_blank\" rel=\"noopener\">Python<\/a> and several programming languages.<\/p>\n<blockquote><p>For Python, <a title=\"PEP 8 -- Style Guide for Python Code - Python.org\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0008\" target=\"_blank\" rel=\"noopener\"><strong>PEP 8<\/strong><\/a> has emerged as the style guide that most projects adhere to; it promotes a very readable and eye-pleasing coding style. Every Python developer should read it at some point; here are the most important points extracted for you:<\/p>\n<ul>\n<li>Use 4-space indentation, and no tabs. 4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.<\/li>\n<li>Wrap lines so that they don&#8217;t exceed 79 characters. This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.<\/li>\n<li>Use blank lines to separate functions and classes, and larger blocks of code inside functions.<\/li>\n<li>When possible, put comments on a line of their own.<\/li>\n<li>Use docstrings.<\/li>\n<li>Use spaces around operators and after commas, but not directly inside bracketing constructs: <tt>a = f(1, <\/tt><tt>2) + g(3, 4)<\/tt>.<\/li>\n<li>Name your classes and functions consistently; the convention is to use <tt>CamelCase<\/tt> for classes and <tt>lower_case_with_underscores<\/tt> for functions and methods. Always use <tt>self<\/tt> as the name for the first method argument (see <a title=\"9. Classes -- Python 3.7.1rc1 documentation - 9.3. A First Look at Classes\" href=\"https:\/\/docs.python.org\/3\/tutorial\/classes.html#tut-firstclasses\" target=\"_blank\" rel=\"noopener\">A First Look at Classes<\/a> for more on classes and methods).<\/li>\n<li>Don&#8217;t use fancy encodings if your code is meant to be used in international environments. Python&#8217;s default, UTF-8, or even plain ASCII work best in any case.<\/li>\n<li>Likewise, don&#8217;t use non-ASCII characters in identifiers if there is only the slightest chance people speaking a different language will read or maintain the code.<\/li>\n<\/ul>\n<\/blockquote>\n<ul>\n<li><small>taken\/quoted from: <a title=\"4. More Control Flow Tools -- Python 3.7.1rc1 documentation\" href=\"https:\/\/docs.python.org\/3\/tutorial\/controlflow.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.python.org\/3\/tutorial\/controlflow.html<\/a><\/small><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The following is true for Python and several programming languages. For Python, PEP 8 has emerged as the style guide that most projects adhere to; it promotes a very readable and eye-pleasing coding style. Every Python developer should read it at some point; here are the most important points extracted for you: Use 4-space indentation, [&hellip;]<\/p>\n","protected":false},"author":7213,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"send_to_group_blog":0,"footnotes":""},"categories":[3,1,17],"tags":[],"class_list":["post-786","post","type-post","status-publish","format-standard","hentry","category-computer-programming","category-cuny","category-open-source"],"_links":{"self":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/users\/7213"}],"replies":[{"embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=786"}],"version-history":[{"count":2,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}