{"id":264,"date":"2023-02-13T09:43:02","date_gmt":"2023-02-13T09:43:02","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/?page_id=264"},"modified":"2023-02-15T09:28:36","modified_gmt":"2023-02-15T09:28:36","slug":"coding-conventions","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/coding-conventions\/","title":{"rendered":"Coding conventions"},"content":{"rendered":"\n<p>While there are lots of ways that the code that you type can work, you should get into a consistent habit so that your code always follows the same rules. When working with others you should agree on how you will format the code.<\/p>\n\n\n\n<p id=\"block-76e52d6d-00ac-442b-a971-476ece0a069a\">Some examples are:<\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-ad3c155f-4bf0-486a-a73a-860d5aaa3e35\"><li>Each level of indent should be 4 spaces<\/li><li>Variable and function names should be lowercase separated by underscores e.g. list_of_animals<\/li><li>Class names should be capitalised and run together e.g. CollisionDetection<\/li><li>Lines of code should be a maximum of 72 characters long<\/li><\/ul>\n\n\n\n<p id=\"block-add3281d-18ef-4497-bcc6-f4337dffb38c\">For an example of more Python coding conventions, look at&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/pep8.org\/\" target=\"_blank\">https:\/\/pep8.org<\/a><\/p>\n\n\n\n<p>You should also use comments to explain what your code is doing. Start a line with a hash # to make it a comment.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<h2 class=\"greentext wp-block-heading\">Good<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># A program to work out the average of \n# two numbers and print the result\n# Author:  J. Smith\n\n# The input numbers\nnumber1 = 13\nnumber2 = 45\n\n# Calculate the average\ntotal = number1 + number2\naverage = total \/ 2\n\n# Print the result\nprint(average)<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<h2 class=\"redtext wp-block-heading\">Bad<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>a=13\nb=45\nprint((a+b)\/2)<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>Compare the two blocks of code. They do the same thing but it is much clearer what the good block of code is doing.<\/p>\n\n\n\n<p class=\"nextlink\"><a href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/operators\/\" data-type=\"page\" data-id=\"272\">Next: Operators<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While there are lots of ways that the code that you type can work, you should get into a consistent habit so that your code always follows the same rules. When working with others you should agree on how you will format the code. Some examples are: Each level of indent should be 4 spaces&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/coding-conventions\/\">Continue reading <span class=\"screen-reader-text\">Coding conventions<\/span><\/a><\/p>\n","protected":false},"author":5710,"featured_media":0,"parent":14,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-264","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/users\/5710"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/comments?post=264"}],"version-history":[{"count":5,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/264\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/264\/revisions\/401"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/14"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/media?parent=264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}