{"id":49,"date":"2023-01-26T22:35:13","date_gmt":"2023-01-26T22:35:13","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/robinstech\/?p=49"},"modified":"2023-01-26T22:35:13","modified_gmt":"2023-01-26T22:35:13","slug":"clean-code-and-code-smells","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/robinstech\/2023\/01\/26\/clean-code-and-code-smells\/","title":{"rendered":"Clean Code And Code Smells"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Clean Code<\/h2>\n\n\n\n<p>Clean code is crucial to developing good programs. Other programmers need to be able to follow the program with ease without needing too many comments. After reading <a href=\"https:\/\/betterprogramming.pub\/12-conventions-for-writing-clean-code-e16c51e3939a\">an article<\/a> about clean code written by Shoaib Mehedi, I noticed that I do follow most of the guidelines. This is due to learning about them in courses because they are often highlighted by professors. <\/p>\n\n\n\n<p>One of the guidelines Mehedi wrote about that I would like to follow is &#8220;magic numbers. Magic numbers are assigned a number without a clear meaning. Mehedi gave the example below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"540\" height=\"247\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6164\/files\/2023\/01\/Screenshot-2023-01-26-123509.png\" alt=\"\" class=\"wp-image-50\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6164\/files\/2023\/01\/Screenshot-2023-01-26-123509.png 540w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6164\/files\/2023\/01\/Screenshot-2023-01-26-123509-300x137.png 300w\" sizes=\"auto, (max-width: 540px) 85vw, 540px\" \/><\/figure>\n\n\n\n<p>I often do the &#8220;bad practice&#8221; simply because I&#8217;m cutting down on the amount of lines of code. However, I can see how the &#8220;good practice&#8221; is better. This is something I will start doing in my code. All of the other twelve guidelines mentioned by Mehedi are things I already do in my code including avoiding using too many comments, large functions, repetitive code, and choosing good names for your variables. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code Smells<\/h2>\n\n\n\n<p>Code smells are issues in the code that can lead to larger issues further down the road. It is especially important to watch out for code smells when working on a large code base. Common code smells are temporary fields, dead code, unnecessary primitive variables, and data clumps. I read <a href=\"https:\/\/refactoring.guru\/refactoring\/smells\">an article<\/a> that further explains these and many more examples. This article is written by an unknown author. <\/p>\n\n\n\n<p>A code smell that I would like to stop doing in my code is having long parameter lists. This doesn&#8217;t happen often, but sometimes I have a function that takes in a lot of parameters. Some thing I can do to avoid this is if I&#8217;m passing in parts of an object, I can instead pass in the whole object for simplicity. In the body of the function, I could separate out the parts of the object that I need. Another thing I can do to solve this is separate out the function into multiple functions so that the multiple functions will have a shorter parameter list. It would be especially good to do this if the body of the original function was too long and doing too many things. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Citations<\/h2>\n\n\n\n<p>\u201cCode Smells.\u201d <em>Refactoring.Guru<\/em>, https:\/\/refactoring.guru\/refactoring\/smells.<\/p>\n\n\n\n<p>Mehedi, Shoaib. \u201c12 Conventions for Writing Clean Code.\u201d <em>Medium<\/em>, Better Programming, 15 May 2021, https:\/\/betterprogramming.pub\/12-conventions-for-writing-clean-code-e16c51e3939a. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clean Code Clean code is crucial to developing good programs. Other programmers need to be able to follow the program with ease without needing too many comments. After reading an article about clean code written by Shoaib Mehedi, I noticed that I do follow most of the guidelines. This is due to learning about them &hellip; <a href=\"https:\/\/blogs.oregonstate.edu\/robinstech\/2023\/01\/26\/clean-code-and-code-smells\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Clean Code And Code Smells&#8221;<\/span><\/a><\/p>\n","protected":false},"author":12926,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/users\/12926"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":2,"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/posts\/49\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/robinstech\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}