{"id":4,"date":"2024-01-19T01:29:40","date_gmt":"2024-01-19T01:29:40","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/?p=4"},"modified":"2024-01-19T01:29:40","modified_gmt":"2024-01-19T01:29:40","slug":"blog-post-1-winter-term","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/2024\/01\/19\/blog-post-1-winter-term\/","title":{"rendered":"Blog Post #1 Winter term"},"content":{"rendered":"\n<p>Since I started my computer science journey, one of the biggest things I have been taught is to write clean code and make sure my code is legible. One of the crucial things I remember learning was making sure my code followed the standards of clean code so that not only the grader could read it but also me in the future.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Embracing Meaningful Variable Names<\/h3>\n\n\n\n<p>The importance of meaningful variable names resonates across various perspectives on clean code. The first chapter in\u00a0<em>Clean Code: A Handbook of Agile Software Craftsmanship<\/em>\u00a0by Robert C. Martin emphasizes the significance of choosing descriptive names for variables. This resonates with the broader notion that clean code should be readable and understandable by developers other than the original author.<\/p>\n\n\n\n<p><strong>One thing I would like to start doing (more often):<\/strong><\/p>\n\n\n\n<p>I want to enhance the communicative aspect of my code by embracing meaningful and expressive variable names. Big Dave Thomas, founder of OTI, stresses the importance of clean code that makes it easy for other developers to enhance it. This involves writing functional code and crafting a narrative that future readers (including myself) can follow effortlessly.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Before\ndef calc_area(w, h):\n    return w * h\n\n# After\ndef calculate_rectangle_area(width, height):\n    return width * height\n<\/pre><\/div>\n\n\n<p>By adopting more expressive names like width and height, I transform the code into a narrative that effectively communicates its purpose and functionality.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Avoiding Code Smell<\/h3>\n\n\n\n<p>The 3rd chapter from\u00a0<em>Refactoring: Improving the Design of Existing Code\u00a0<\/em>by Martin Fowler highlights the challenges posed by long parameter lists in methods. I commit to refraining from creating methods with excessive parameters to prevent this. Instead, I explore techniques like introducing parameter objects, preserving whole objects, or using other refactorings to keep the parameter lists concise.<\/p>\n\n\n\n<p><strong>One thing I want to avoid doing:<\/strong><\/p>\n\n\n\n<p>I want to avoid doing the &#8220;Duplicate Code&#8221; smell, where identical or similar codes exist in multiple places in the codebase. As per the reading, duplicated code can lead to maintenance challenges, as changes need to be applied in multiple locations. Refactoring to eliminate duplication can improve code maintainability.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n## Code before\ndef calculate_area(radius):\n    return 3.14 * radius * radius\n\ndef calculate_volume(radius, height):\n    return 3.14 * radius * radius * height\n\n##Code After\nPI = 3.14\n\ndef calculate_area(radius):\n    return PI * radius * radius\n\ndef calculate_volume(radius, height):\n    return PI * radius * radius * height\n<\/pre><\/div>\n\n\n<p>In this example, the refactored code introduces a constant PI to replace the magic number 3.14 used for calculations. This makes the code more readable and maintainable and avoids the duplication of the magic number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Incorporating meaningful variable names and avoiding long, convoluted methods aligns with industry leaders&#8217; broader clean code principles. By embracing these practices, I can contribute to a codebase that is functional, readable, maintainable, and a testament to our commitment to code craftsmanship.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since I started my computer science journey, one of the biggest things I have been taught is to write clean code and make sure my code is legible. One of the crucial things I remember learning was making sure my code followed the standards of clean code so that not only the grader could read [&hellip;]<\/p>\n","protected":false},"author":13907,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/posts\/4","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/users\/13907"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/comments?post=4"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":6,"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/posts\/4\/revisions\/6"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/capstoneblog2ishanshi\/wp-json\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}