The Art of Coding: Clean Code.

In the everyday life of a computer science enthusiast we are caught up in complex stuff like algorithms and coding languages, but there is a crucial aspect that we cannot overlook, writing clean code. In this blog post, I will show you some coding principles that make your code look good and make life easier for you and whoever reads your code.

  1. Clean Code is not just a fancy choice, it’s a must. Robert C. Martin says, “Clean code is simple and direct. It reads like well-written prose.” This basically means writing a clean code isn’t just for others, it’s a great help to you as well.
  2. Naming things by what they are supposed to do makes total sense. Dont aim for cryptic names, go for clarity. Think of good names as a map, it tells you what is what without a guide.

    Python Example:
    <<
    #Confusing variable name
    x = 5
    #Clear variable name
    total_items = 5
    >>
  3. Consistent formatting is your code’s best friend. Follow a set of indenting and formatting rules and stick by it till the end. Most IDE’s or coding tools make your code look neat automatically but putting some effort yourself goes a long way.

    Java example:
    <<
    // Messy formatting
    public void exampleMethod(){
    if(condition){
    statement();
    }
    }
    // Clean formatting
    public void exampleMethod() {
    if (condition) {
    statement();
    }
    >>

  4. Break things down and chop your code into smaller bits (this part exists in all of my blog posts by now). Each bit needs to have one main job or function. This makes your code easier to understand and saves you from later headaches.
  5. A little comment goes a long way. Try to think of comments as salt, a pinch is just right, and a lot ruins the dish (and gives you high blood pressure). Use your comments for tricky parts and remember to keep them updated.
  6. A lot of us are familiar with Legos which makes Test-Driven Development somewhat easier to grasp. Before building a great pyramid, try to plan it out with smaller bricks (tests). Not only does it ensure your code works but it helps in keeping things organized.


To conclude: Diving deeper into the coding world the smartest move you can make is writing clean code. Not only to impress the others but to make your life smoother. To put this in other words my generation understands writing clean code is the “ultimate flex”. Until next time keep it clean.

Ano out.

References: 
“The Clean Code Blog

by Robert C. Martin (Uncle Bob)” – https://blog.cleancoder.com/

Leave a comment