{"id":19,"date":"2025-01-17T02:02:47","date_gmt":"2025-01-17T02:02:47","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/?p=19"},"modified":"2025-01-17T02:16:20","modified_gmt":"2025-01-17T02:16:20","slug":"embracing-clean-code-practices-a-personal-reflection","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/2025\/01\/17\/embracing-clean-code-practices-a-personal-reflection\/","title":{"rendered":"Embracing Clean Code Practices: A Personal Reflection"},"content":{"rendered":"\n<p class=\"has-medium-font-size\">Greetings Everyone,<\/p>\n\n\n\n<p>As I continue to grow as a programmer, I&#8217;ve been reflecting on how I approach writing and maintaining code. Recently, I came across some insightful articles about clean code and code smells that challenged me to reevaluate my coding habits. Today, I want to share one practice I aim to incorporate more often and one I want to avoid, based on the lessons from these resources.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Cleaning Things Up: Writing Small, Focused Functions (Clean Code)<\/h3>\n\n\n\n<p>One thing that stood out to me from <a href=\"https:\/\/dzone.com\/articles\/five-principles-of-clean-code\">DZone&#8217;s article on clean code principles<\/a> and <a href=\"https:\/\/www.freecodecamp.org\/news\/clean-coding-for-beginners\/\">freeCodeCamp\u2019s beginner\u2019s guide<\/a> is the importance of writing small, focused functions. Functions that do one thing and do it well are not only easier to read, but also simpler to test and debug.<\/p>\n\n\n\n<p>Here\u2019s an example of a refactor I\u2019d like to adopt more often:<\/p>\n\n\n\n<p><strong>Before (A Large, Complex Function):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"643\" height=\"317\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image.png\" alt=\"\" class=\"wp-image-20\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image.png 643w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-300x148.png 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/figure>\n\n\n\n<p><strong>After (Smaller, Focused Functions):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"350\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-1.png\" alt=\"\" class=\"wp-image-21\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-1.png 647w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-1-300x162.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<p>This approach aligns with the Single Responsibility Principle and makes the code much easier to maintain.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Does Your Code Stink? Stop Ignoring Code Smells<\/h3>\n\n\n\n<p>Another eye-opener was understanding the impact of code smells, as discussed in <a href=\"https:\/\/learn.codesignal.com\/preview\/lessons\/3603\/understanding-code-smells-identifying-the-need-for-refactoring-in-your-code\">CodeSignal\u2019s guide to identifying code smells<\/a> and <a href=\"https:\/\/dev.to\/hitheshkumar\/code-smells-warning-signs-in-your-codebase-you-cant-ignore-g4l\">Hithesh Kumar\u2019s insights<\/a>. Ignoring code smells like long methods, duplicate code, or unnecessary comments can lead to technical debt and make the codebase harder to work with.<\/p>\n\n\n\n<p>For example, consider this snippet:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"151\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-2.png\" alt=\"\" class=\"wp-image-22\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-2.png 651w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-2-300x70.png 300w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<p><strong>Code with Smells (Duplicate Code):<\/strong><\/p>\n\n\n\n<p>This duplication violates the DRY (Don\u2019t Repeat Yourself) principle. Instead, we can refactor:<\/p>\n\n\n\n<p><strong>Refactored Code:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"252\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-3.png\" alt=\"\" class=\"wp-image-23\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-3.png 650w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8152\/files\/2025\/01\/image-3-300x116.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<p>By addressing code smells proactively, I can reduce future headaches and improve the overall quality of my work.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Why These Changes Matter<\/h3>\n\n\n\n<p>Writing small, focused functions fosters better collaboration, as teammates can quickly understand and modify the code. Addressing code smells ensures a healthier codebase, saving time and effort in the long run. These habits also reflect professionalism, a critical trait as I transition into the data science field, where clean and maintainable code is essential for reproducibility and scaling.<\/p>\n\n\n\n<p>As I move forward, I\u2019ll strive to implement these practices consistently, logging my progress in my &#8220;lessons learned&#8221; journal to ensure continuous improvement. If you have any tips or experiences with clean code or tackling code smells, I\u2019d love to hear about them in the comments!<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\">Cheers, Trent<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Greetings Everyone, As I continue to grow as a programmer, I&#8217;ve been reflecting on how I approach writing and maintaining code. Recently, I came across some insightful articles about clean code and code smells that challenged me to reevaluate my coding habits. Today, I want to share one practice I aim to incorporate more often [&hellip;]<\/p>\n","protected":false},"author":14542,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-assignment-prompts"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/users\/14542"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":9,"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":35,"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/posts\/19\/revisions\/35"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/trentschmidt\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}