Categories
Uncategorized

Writing Clean Code

As my team and I begin to dive deep into development, I have identified a few coding habits that I want to change to avoid code smells and write clean code.

I like to think that I keep my code pretty clean. I use descriptive names, consistent indenting, sufficient white space and keep line counts to a minimum, all the things they drill into you in you first computer science class. But after reading an article written by software developer Claudia Sanjuan “10 Tips for Writing Cleaner Code in Any Programming Language“, one tip that I took away is to make sure that functions only serve one purpose, and keep them short. I think that when writing code, my first instinct is to solve my problem in one function. This leads to long complex functions, when the problem could have been solved in a manner of 1-2 simpler functions. Paying attention to when my functions should be split up into smaller, simpler functions is something I am going to work on going forward.

One habit I am working on breaking is saving dead code. An article “31 Code Smells All Developers Must Watch Out For” from software engineering blog Pragmatic Ways, lists dead code – code that is not being used in the programming or is commented out – as #4. I have a habit of commenting out code and saving it for later, worried that I might want to use it instead. But as the article mentions, that is the purpose of version control. In the future, I plan to make sure that I delete dead code I don’t need to clean up my codebase.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *