{"id":13,"date":"2025-01-14T03:01:55","date_gmt":"2025-01-14T03:01:55","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/?p=13"},"modified":"2025-01-14T03:01:55","modified_gmt":"2025-01-14T03:01:55","slug":"programming-habits","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/2025\/01\/14\/programming-habits\/","title":{"rendered":"Programming Habits"},"content":{"rendered":"\n<p>Comments, naming conventions and white space have been taught to us ever since we began studying CS at Oregon State. Good coding habits have been a subject of every class, usually in the form of a course page describing code style expectations, just like an English class might describe what citation style to use. While I am good at reading those pages and writing out my comments, there are some more time-consuming habits I need to apply.<\/p>\n\n\n\n<p>DRY is an acronym commonly used in this subject, and it stands for Don&#8217;t Repeat Yourself. In practice this involves writing reusable code. If there is a common operation in your code (or even a common value), it is important to create functions to perform this operation instead of writing it many times throughout your code (<a href=\"https:\/\/medium.com\/@josueparra2892\/20-best-programming-practices-407df688b96e\">https:\/\/medium.com\/@josueparra2892\/20-best-programming-practices-407df688b96e<\/a> item #3).<\/p>\n\n\n\n<p>I recently violated this principle horribly in my Programming Language Fundamentals class. Because each assignment in this class asks the student to write a program in a different, obscure language, code cleanliness is a lower priority as I was just trying to get the foreign code to work. Before I submitted my assignment, I noticed about a dozen repeating lines throughout the 100 or so lines of code. I had taken an iterative approach to writing code, when I could have planned much better to organize my code into reusable chunks. This is a habit that I practice often, but even after a few years of coding I still slip.<\/p>\n\n\n\n<p>While I write decently organized code with understandable variable names and comments, what don&#8217;t I do? While reading through &#8220;15 Bad coding practices you should avoid,&#8221; I was reminded about a gap in my skills: Error Handling. So much of the code I write is for academia, and therefore there are most often rubrics and automated tests in Gradescope with which I can evaluate my code. However, I am aware that moving into a career Software Development, it is important to bulletproof your code against edge-cases and unexpected errors. This means that instead of your program crashing, it will be able to handle these errors gracefully and provide a user with useful information to help them correct their actions (<a href=\"https:\/\/codedamn.com\/news\/programming\/bad-coding-practices-examples-you-should-avoid\">https:\/\/codedamn.com\/news\/programming\/bad-coding-practices-examples-you-should-avoid<\/a> line #5). Unit tests are useful for testing many possible inputs in a program and can help identify gaps in the software.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Comments, naming conventions and white space have been taught to us ever since we began studying CS at Oregon State. Good coding habits have been a subject of every class, usually in the form of a course page describing code style expectations, just like an English class might describe what citation style to use. While [&hellip;]<\/p>\n","protected":false},"author":14511,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/users\/14511"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/posts\/13\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/jpcapstone\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}