{"id":1649,"date":"2021-02-20T21:23:24","date_gmt":"2021-02-20T21:23:24","guid":{"rendered":"http:\/\/learnlearn.uk\/alevelcs\/?page_id=1649"},"modified":"2021-02-20T21:49:29","modified_gmt":"2021-02-20T21:49:29","slug":"efficient-code","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/","title":{"rendered":"Efficient Code"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Intro<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Writing\u00a0 Efficient Code<\/h3>\n<p>Efficiency in coding is very important. It allows you to speed up your development time and makes your code easier to read, debug and maintain. There are a number of different ways in which you can make your code more efficient, including:<\/p>\n<ul>\n<li>Use of loops for repeated actions<\/li>\n<li>Use of data structures instead of separate variables<\/li>\n<li>Use of compound data structures<\/li>\n<li>Use of functions &amp; procedures<\/li>\n<li>Use of in-built features \/ external code libraries<\/li>\n<li>Use of recursion<\/li>\n<li>Use of object orientated coding.<\/li>\n<li>Separation of data from the code<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">Loops<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Loops<\/h3>\n<p>Pretty much the first efficiency technique any beginner programmer learns is how to use a loop to improve efficiency.<\/p>\n<ul>\n<li>You can use Unconditional loops(e.g. while loops) to repeatedly ask a question until a valid response is inputted.<\/li>\n<li>You can use Iteration (for loops) to perform the same(or similar) action for a number of different items in a list.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Structures<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Data Structures<\/h3>\n<p>Data structures allow the user to store multiple pieces of the same type of data using one single identifier name, rather than through multiple variables.<\/p>\n<ul>\n<li>They work with loops making repetition more simple to perform.<\/li>\n<li>The are quicker and easier to debug\/maintain.<\/li>\n<\/ul>\n<p><strong>Compound Data Structures<\/strong><\/p>\n<p>Compound data structures, including 2 Dimensional arrays\u00a0 and dictionaries within dictionaries, allow for more efficient, maintainable and extendable code than separate arrays.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Functions<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Functions &amp; Procedures<\/h3>\n<p>Functions and procedures make your code more efficient because:<\/p>\n<ul>\n<li>They allow repeated use throughout the file (and in order files)<\/li>\n<li>They make your code more readable<\/li>\n<li>Can be called within other functions making them even more powerful.<\/li>\n<li>Functions allow the editing of the internal workings of a function without affect other\u00a0 logic outside of the function.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Libraries<\/h2>\n<div class=\"tabcontent\">\n\n<h3>External Libraries<\/h3>\n<p>Making use of external modules and optional downloadable modules allows for far more efficient coding, especially in larger projects.<\/p>\n<ul>\n<li>You can implement functionality without reinventing the wheel.<\/li>\n<li>You can use features that you don&#8217;t know how to implement<\/li>\n<li>If an update of bug fix is rolled out, all users of the module can benefit from the improvements.<\/li>\n<\/ul>\n<p>Of course there are risks associated with use external sources of a code, including:<\/p>\n<p>You don&#8217;t know what the code is doing &#8211; it could be doing something malicious or malfunctioning in some way.<br \/>\nYou can&#8217;t update the library yourself if there is an issue &#8211; you have to wait for a fix to be implemented.<br \/>\nSome libraries have a large storage \/memory \/ CPU overhead in comparison to custom code implementations.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Recursion<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Recursion<\/h3>\n<p>Some programming problems can only be solved , or be solved more efficiently through the use of recursion, where a function calls itself, for example:<\/p>\n<ul>\n<li>Walking through directory trees<\/li>\n<li>Implementing Stacks<\/li>\n<li>Binary search<\/li>\n<li>Divide and conquer sorting algorithms, such as merge sort.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/learnlearn.uk\/alevelcs\/recursion\/\">For more information see the page on recursion.<\/a><\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">OOP<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Object Orientated Programming<\/h3>\n<p>In some situations, such as when you are trying to model real life objects or environments, then using object orientated programming techniques can massively improve the efficiency of your code. You code can become far more readable and adaptable.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Separation<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Separation of data from code<\/h3>\n<p>When writing programs it is often beneficial to store data in a separate file, rather than in the program itself. This means that if the data needs to be changed then it can be done quickly and without risking damaging the code base. Using external data storage also makings implementing multilingual programs much easier, as when the program is loaded\/installed a separate language file can be specified.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing\u00a0 Efficient Code Efficiency in coding is very important. It allows you to speed up your development time and makes your code easier to read, debug and maintain. There are a number of different ways in which you can make your code more efficient, including: Use of loops for repeated actions Use of data structures&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Efficient Code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Efficient Code - A Level Computer Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Efficient Code - A Level Computer Science\" \/>\n<meta property=\"og:description\" content=\"Writing\u00a0 Efficient Code Efficiency in coding is very important. It allows you to speed up your development time and makes your code easier to read, debug and maintain. There are a number of different ways in which you can make your code more efficient, including: Use of loops for repeated actions Use of data structures&hellip;&nbsp;Read More &raquo;Efficient Code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/\" \/>\n<meta property=\"og:site_name\" content=\"A Level Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-20T21:49:29+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/\",\"name\":\"Efficient Code - A Level Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\"},\"datePublished\":\"2021-02-20T21:23:24+00:00\",\"dateModified\":\"2021-02-20T21:49:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"A Level Computer Science Home\",\"item\":\"https:\/\/learnlearn.uk\/alevelcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Efficient Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"name\":\"A Level Computer Science\",\"description\":\"CIE Specification\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\",\"name\":\"A Level Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"A Level Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Efficient Code - A Level Computer Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/","og_locale":"en_GB","og_type":"article","og_title":"Efficient Code - A Level Computer Science","og_description":"Writing\u00a0 Efficient Code Efficiency in coding is very important. It allows you to speed up your development time and makes your code easier to read, debug and maintain. There are a number of different ways in which you can make your code more efficient, including: Use of loops for repeated actions Use of data structures&hellip;&nbsp;Read More &raquo;Efficient Code","og_url":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/","og_site_name":"A Level Computer Science","article_modified_time":"2021-02-20T21:49:29+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/","url":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/","name":"Efficient Code - A Level Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#website"},"datePublished":"2021-02-20T21:23:24+00:00","dateModified":"2021-02-20T21:49:29+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/alevelcs\/efficient-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"A Level Computer Science Home","item":"https:\/\/learnlearn.uk\/alevelcs\/"},{"@type":"ListItem","position":2,"name":"Efficient Code"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/alevelcs\/#website","url":"https:\/\/learnlearn.uk\/alevelcs\/","name":"A Level Computer Science","description":"CIE Specification","publisher":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization","name":"A Level Computer Science","url":"https:\/\/learnlearn.uk\/alevelcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"A Level Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/alevelcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Writing\u00a0 Efficient Code Efficiency in coding is very important. It allows you to speed up your development time and makes your code easier to read, debug and maintain. There are a number of different ways in which you can make your code more efficient, including: Use of loops for repeated actions Use of data structures&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1649"}],"collection":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/comments?post=1649"}],"version-history":[{"count":5,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1649\/revisions"}],"predecessor-version":[{"id":1655,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/1649\/revisions\/1655"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/media?parent=1649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}