{"id":32,"date":"2023-01-27T07:47:19","date_gmt":"2023-01-27T07:47:19","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/?p=32"},"modified":"2023-01-27T07:47:19","modified_gmt":"2023-01-27T07:47:19","slug":"winter-blog-1","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/2023\/01\/27\/winter-blog-1\/","title":{"rendered":"Winter &#8211; Blog 1"},"content":{"rendered":"\n<p><strong>Clean Code<\/strong><\/p>\n\n\n\n<p><p dir=\"ltr\" style=\"line-height:1.38;text-align: justify;margin-top:0pt;margin-bottom:0pt\" id=\"docs-internal-guid-69196a3b-7fff-f08a-4acf-d0d5a1cc1543\"><span style=\"font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline\">I would like to start keeping functions more easier to read, better commented, and shorter. I can think of many times where I have these long functions that are written out, that eventually do what they are supposed to, but are long and sometimes hard to read. We can see in this example below of a function that loads data from a url.\u00a0<\/span><\/p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"805\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/splitting-function-1.jpg\" alt=\"\" class=\"wp-image-33\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/splitting-function-1.jpg 678w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/splitting-function-1-253x300.jpg 253w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/figure>\n\n\n\n<p>Splitting up this function into smaller one and done tasks is a great way to increase readability and maintainability of said code. Looking at the beginning of the load_data function we could start by splitting up the download and unzip actions of the function.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"670\" height=\"113\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/splitting-2.jpg\" alt=\"\" class=\"wp-image-34\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/splitting-2.jpg 670w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/splitting-2-300x51.jpg 300w\" sizes=\"auto, (max-width: 670px) 100vw, 670px\" \/><\/figure>\n\n\n\n<p><span id=\"docs-internal-guid-efc87cda-7fff-f9de-f975-abedb387a9e3\" style=\"font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline\">Seen below we now have the download action of load_data() into its own single task function.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"679\" height=\"63\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/spli.jpg\" alt=\"\" class=\"wp-image-35\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/spli.jpg 679w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/spli-300x28.jpg 300w\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" \/><\/figure>\n\n\n\n<p>We could continue on with splitting load_data() into functions into smaller single task functions but you get the idea right? In the end, splitting up large functions like this example is an easy thing to do, and something that I will definitely start practicing!<\/p>\n\n\n\n<p><strong>DATA DUMps<\/strong><\/p>\n\n\n\n<p>One of the code smell examples was data clumping. Data clumping appears to be a common mistake, I sure know I do this! Clumping is when there are multiple method calls that access the same set of parameters or when related data is grouped together. An example of this code smell can be seen below.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"329\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex.jpg\" alt=\"\" class=\"wp-image-36\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex.jpg 748w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex-300x132.jpg 300w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/figure>\n\n\n\n<p>Here we have an example of an object that represents a booking aspect of a hotel. There are two different time parameters that are needed for the complete booking time. Splitting these two parameters away from the booking class and into a class of their own would make the code easier to read and maintain.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"749\" height=\"257\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex2.jpg\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex2.jpg 749w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex2-300x103.jpg 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/figure>\n\n\n\n<p>Creating this new class for the time frame gives us a new entity that interacts with the booking class. The below \u201cpolished\u201d example definitely provides us with a cleaner and more readable section of code!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"758\" height=\"155\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex3.jpg\" alt=\"\" class=\"wp-image-38\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex3.jpg 758w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/6237\/files\/2023\/01\/data-clump-ex3-300x61.jpg 300w\" sizes=\"auto, (max-width: 758px) 100vw, 758px\" \/><\/figure>\n\n\n\n<p>I can already think of times that I\u2019ve had overcrowded clumps of data throughout my code. So much that when trying to troubleshoot or read through my code becomes a tedious and confusing process. So remembering what I have learned today I hope this helps me to write cleaner, more readable, and less clumpy code.<\/p>\n\n\n\n<p>Good luck out there!<\/p>\n\n\n\n<p>Brahm<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Sources &#8211;&nbsp;<\/p>\n\n\n\n<p><a href=\"https:\/\/www.pluralsight.com\/blog\/software-development\/10-steps-to-clean-code\">https:\/\/www.pluralsight.com\/blog\/software-development\/10-steps-to-clean-code<\/a><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-apiumhub wp-block-embed-apiumhub\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/apiumhub.com\/tech-blog-barcelona\/code-smells\/\n<\/div><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.servicenow.com\/community\/developer-articles\/code-smells-refactoring-data-clump\">https:\/\/www.servicenow.com\/community\/developer-articles\/code-smells-refactoring-data-clump<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.servicenow.com\/community\/developer-articles\/code-smells-refactoring-data-clumps-including-parameter-lists\/ta-p\/2320891\">s-including-parameter-lists\/ta-p\/2320891<\/a><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-simple-programmer wp-block-embed-simple-programmer\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"pCP9WTDGmg\"><a href=\"https:\/\/simpleprogrammer.com\/clean-code-principles-better-programmer\/\">Clean Code Principles: Be a Better Programmer<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Clean Code Principles: Be a Better Programmer&#8221; &#8212; Simple Programmer\" src=\"https:\/\/simpleprogrammer.com\/clean-code-principles-better-programmer\/embed\/#?secret=d7vnu4h0sb#?secret=pCP9WTDGmg\" data-secret=\"pCP9WTDGmg\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Splitting functions up example &#8211;&nbsp;<\/p>\n\n\n\n<p><a href=\"https:\/\/towardsdatascience.com\/python-clean-code-6-best-practices-to-make-your-python-functions-more-readable-7ea4c6171d60\">https:\/\/towardsdatascience.com\/python-clean-code-6-best-practices-to-make-your-python-functions-more-readable-7ea4c6171d60<\/a><\/p>\n\n\n\n<p>Data clump code smell example &#8211; <\/p>\n\n\n\n<p>https:\/\/blog.jetbrains.com\/dotnet\/2018\/07\/02\/join-data-items-want-go-together-code-smells-series\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clean Code I would like to start keeping functions more easier to read, better commented, and shorter. I can think of many times where I have these long functions that are written out, that eventually do what they are supposed to, but are long and sometimes hard to read. We can see in this example [&hellip;]<\/p>\n","protected":false},"author":12995,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/users\/12995"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/posts\/32\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/brahmrifino\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}