{"id":16,"date":"2025-01-17T05:32:24","date_gmt":"2025-01-17T05:32:24","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/lindsasc\/?p=16"},"modified":"2025-01-17T05:32:24","modified_gmt":"2025-01-17T05:32:24","slug":"blog-post-1-2","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/lindsasc\/2025\/01\/17\/blog-post-1-2\/","title":{"rendered":"Blog Post #1"},"content":{"rendered":"\n<p class=\"has-text-align-center\">Winter 2025 Term &#8211; Scott Lindsay &#8211; CS462<\/p>\n\n\n\n<p><strong>Introduction<\/strong><\/p>\n\n\n\n<p>Looking back at my older code, I\u2019ve often found myself struggling to understand what I wrote. Writing clean, maintainable code is a crucial skill for any developer, but achieving it consistently can be difficult. What exactly makes code \u201cclean\u201d? How can we identify and eliminate bad coding practices, commonly known as \u201ccode smells\u201d? In this post, I\u2019ll share some basic insights from my research on clean code and code smells which I believe will be beneficial to incorporate into my workflow and also what I plan to avoid.<\/p>\n\n\n\n<p><strong>Clean Code: Focusing On The Human Element<\/strong><\/p>\n\n\n\n<p>One of the core principles from Robert Martin\u2019s&nbsp;<em>Clean Code: A Handbook of Agile Software Craftsmanship<\/em>&nbsp;is that code should be written for humans, not just computers. This means using meaningful variable and function names, writing small and single-purpose functions, and avoiding unnecessary complexity.<\/p>\n\n\n\n<p><strong>Example of Bad Practice: Unclear variable names, no comments<\/strong><\/p>\n\n\n\n<p>def calc(x, y):<br>return x * y<\/p>\n\n\n\n<p><strong>Improved Version: Descriptive names and clear functionality<\/strong><\/p>\n\n\n\n<p>def multiply_numbers(factor1, factor2):<br>&#8220;&#8221;&#8221;<br>Multiplies two numbers and returns the result.<br>&#8220;&#8221;&#8221;<br>return factor1 * factor2<\/p>\n\n\n\n<p><strong>Code Smells: Recognizing and Avoiding Bad Practices<\/strong><\/p>\n\n\n\n<p>Martin Fowler\u2019s\u00a0<em>Refactoring: Improving the Design of Existing Code<\/em>\u00a0describes various code smells as reliable indicators of bad coding practices that lead to maintainability issues. One of the most common code smells is\u00a0caused by functions getting too long and becoming bloated with too much responsibility.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Bad Practice Ex: Long method doing too much<br><\/strong>public void processUserRegistration(User user) {<\/p>\n\n\n\n<p><br><strong>Validate user<br><\/strong>if (user == null || user.getEmail().isEmpty()) {<br>throw new IllegalArgumentException(&#8220;Invalid user&#8221;);<br>}<\/p>\n\n\n\n<p><strong>Save user to database<br><\/strong>UserRepository repository = new UserRepository();<br>repository.save(user);<\/p>\n\n\n\n<p><strong>Send welcome email<br><\/strong>EmailService emailService = new EmailService();<br>emailService.sendWelcomeEmail(user);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><strong>What I Will Start Doing: Writing Smaller Functions<\/strong><\/p>\n\n\n\n<p>From my research, I\u2019ve realized the importance of writing small, single-purpose functions. This makes code easier to read, test, and maintain. Going forward, I will be more intentional about breaking down large methods into smaller, more modular functions and keep an eye on the length as I code each function.<\/p>\n\n\n\n<p><strong>What I Will Avoid: Ignoring Code Smells<\/strong><\/p>\n\n\n\n<p>In the past, I\u2019ve sometimes ignored minor inefficiencies, thinking they wouldn\u2019t matter much. However, I now understand that bad practices accumulate over time, making future modifications harder. I will actively look for and eliminate code smells, especially long methods and poor naming conventions.<\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>I&#8217;ve realized that clean code is not just about making things look nice; it significantly improves maintainability and reduces technical debt. By writing meaningful function names, breaking down long methods, and avoiding common code smells, we can make our codebases more efficient and understandable.<\/p>\n\n\n\n<p>I hope you found my post helpful and appreciate any comments or feedback. <br><br>&#8211; Scott Lindsay<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Winter 2025 Term &#8211; Scott Lindsay &#8211; CS462 Introduction Looking back at my older code, I\u2019ve often found myself struggling to understand what I wrote. Writing clean, maintainable code is a crucial skill for any developer, but achieving it consistently can be difficult. What exactly makes code \u201cclean\u201d? How can we identify and eliminate bad [&hellip;]<\/p>\n","protected":false},"author":14533,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/users\/14533"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":17,"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/posts\/16\/revisions\/17"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/lindsasc\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}