Practical Application of Clean Code Principles

Posted on Posted in Stories

Small Step Leads to a Bigger Accomplishments”

I remember when my boss told this phrase to me  during my evaluation. Most of the time, my role is a support member to existing projects. And since the project is already done, I just add up a little fragment of code in order to resolve bug reported. And because of that, it’s difficult for me to practice clean coding. However, he told me that I can learn to write clean codes from those existing codes. Identify what are the parts that need to be improved and try to avoid such practices. And also acquire some techniques in enhancing it.

Being involved in a company wherein its vision is to be globally recognized in building creative software applications, demands us to improve our skills. The need to improve our programming skills made me stumble upon this book entitled “Clean Code: A Handbook of Agile Software Craftsmanship” by Robert C. Martin.

Here are some of the concepts that I am able to relate in my career as a programmer:

Method/Function — Have you already experienced wandering around a method that consist of hundreds of lines. Methods that contain a lot of abstractions and too many things going on and you’re trying to understand what these complex codes do until your eyes starts to get teary because of prolong staring? In addition to this, confusing names are also used, which makes you even more stirred up. Programmers should avoid using these names and start to practice using a more meaningful names. In  projects we accomplished, every method has a name which describes parameters that the method accepts and also the main procedure it does. An example of this is the method loadByUserName(String userName). At one glance , you already have an idea that this method accept a parameter username that will be use to retrieve a particular user. This demonstrates the usefulness of this principle.

Comments — Comments are usually taken for granted. Programmers easily neglect the importance of a comment until it’s needed. For example, I normally see a comment in the beginning of the code that tells you a little description of the codes, who is/are the author/s and other details of the codes.Even so, as I continue to program, I often forgot to place my name in that particular comment section. And because of that, whenever someone needs to clarify something regarding the code, he/she do not have an idea who to consult with. Therefore, the coder was left no choice but to study it, and if he can’t , just rely to guess.Sometimes, that minimal negligence leads to a more serious problem. Taking responsibility is an important part of being a professional.

Formatting — Is this necessary? My answer is yes. Why? Based from experience, it’s such a pleasant thing to see that your code is arranged properly. Brackets are well-aligned. Conditionals are placed in such a way that you can easily identify their scope the same with the declaration of variables. These little things would help  programmers a lot in their coding. One advantage of this is that they are readable. You can easily pin point codes that are related. And from that, you can now  understand the codes without difficulty and can work on it right away.

Handling Errors — Lately, I realized that this specific concept is very important to me as a programmer. Knowing what the particular error is, will provide you a clearer way to formulate a solution to that problem. I believe that there’s no such thing as a perfect code because for me, bugs are inevitable. The only thing that we could do is to handle them properly. Try to generate a step that you can deduce a specific one from a more general one. And from there, you can now proceed in debugging and resolving the problem.

These principles are often forgotten and ignored. Even so, these simple ideas are as important just like any other components in programming. So next time that you’ll be doing some programming again, always keep these tips in mind and continue to practice writing clean codes as it will make you a better and happier developer.

One thought on “Practical Application of Clean Code Principles

  1. I would say that code which is already in production is a better venue to practice good software development practices and refactoring as a whole than a new code base.

    You can also learn something from Working Effectively with Legacy Code by Michael Feathers and Refactoring by Martin Fowler.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.