{"id":31,"date":"2024-01-19T00:09:51","date_gmt":"2024-01-19T00:09:51","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/?p=31"},"modified":"2024-01-19T00:09:51","modified_gmt":"2024-01-19T00:09:51","slug":"cs-462-blog-post-1","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/2024\/01\/19\/cs-462-blog-post-1\/","title":{"rendered":"CS 462 &#8211; Blog Post 1"},"content":{"rendered":"\n<p>An article I read about clean code comes from freeCodeCamp.org [1]. This article provides several tips and best practices for writing clean code. One tip from the article that I want to work on more often is the efficiency of my code. I can create effective code but I often know that it can be more efficient. The article gives an example of inefficient and efficient code shown in figure 1 below. The efficient code only requires one iteration over the array and has fewer lines of code which helps with its simplicity. Improving my efficiency will not only help my code run faster but can help my code simplicity which will make it easy to understand and follow.<\/p>\n\n\n\n<p>I also have some practices that I want to avoid while coding as an article on code smells from refactoring.guru [2] points out. One of these practices that I want to avoid is having code bloat, specifically long functions. In previous coding assignments I would often place all code for one task in one main function instead of creating helper functions that can help reduce the main function. Doing this creates a long and bloated main function that is harder to understand and follow. Creating helper functions to reduce the main function will help me avoid code bloat and can help me improve code readability or simplicity.<\/p>\n\n\n\n<div style=\"height:55px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>\/\/ Inefficient Example<br>function sumArrayInefficient(array) {<br>let sum = 0;<br>for (let i = 0; i &lt; array.length; i++) {<br>sum += array[i];<br>}<br>return sum;<br>}<\/p>\n\n\n\n<p>\/\/ Efficient example<br>function sumArrayEfficient(array) {<br>return array.reduce((a, b) =&gt; a + b, 0);<br>}<\/p>\n<\/div>\n\n\n\n<p>Figure 1 \u2013 Inefficient vs Efficient code example<\/p>\n<\/div>\n\n\n\n<div style=\"height:55px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-text-align-left\">Citation<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>How to Write Clean Code \u2013 Tips and Best Practices (Full Handbook). (2023, May 15). freeCodeCamp.org. <a href=\"https:\/\/www.freecodecamp.org\/news\/how-to-write-clean-code\/\">https:\/\/www.freecodecamp.org\/news\/how-to-write-clean-code\/<\/a><\/li>\n\n\n\n<li>Code Smells. (n.d.). Code Smells. https:\/\/refactoring.guru\/refactoring\/smells<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>An article I read about clean code comes from freeCodeCamp.org [1]. This article provides several tips and best practices for writing clean code. One tip from the article that I want to work on more often is the efficiency of my code. I can create effective code but I often know that it can be [&hellip;]<\/p>\n","protected":false},"author":13853,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/users\/13853"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":2,"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/posts\/31\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nickfrancisco\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}