Code is read a million times, written once

Code is read more often than it is written. Many people start coding without think about the algorithm. Some try to put comments more than code and think it is good. But a clean code is self documented. Lets have an example:

Above code has a lot of comments but little time consuming to understand but the same code can be written as below:

It does not have comments but still understandable to everyone.

So , when should we add comments? When the code is complex and not easily understandable or may be confused.

Code should be modular / independent-

Try to put less global variables and no code should spread all over the place. Classes and functions makes code more reusable.Modular code is easy to test, easy to debug, easy to extend. That’s because if a part of the code goes out of date, you can update that, without worrying about breaking a million other things.

If you go work for any of the top software companies, only about 30% of your time will be spent coding. For an average project, you will spend:

  • 30-40% of your time designing the solution. Yes, this much. The more time you spend early on, the less you need to spend fixing bugs later.
  • Another 30-40% writing the code, which includes writing tests.
  • 10-20% debugging and testing.
  • 10% in code reviews.

Coding is an art. Being proud of your work, doing work like an artisan is what separates us from code monkeys.

Say you hired someone to build our home. The builder turns up, his pants hanging down to his ass, cheap rolled up cigarette hanging from his mouth,  and says “Yup, we’ll build your house in a week.”

And he starts throwing bricks willy nilly, in the shape of a wall. But a few days later, he realises he is going at a 30% angle, so throws everything down and starts again. A few days later, he realises he built a wall where there should have been a window. The builder laughs and says, “Mistakes happen. What are you gonna do?”

What will you do? Will you ask him why he didn’t design blueprints of the house before he started throwing bricks around?

“Hey, I’m a builder, not a designer,” he says.

Do you see now how many business owners see programmers? Just like that builder, pants hanging down, boasting, “Yeah, we’ll build that website in a week. No problem.”

This is a mix post but might be helpful for the beginners who is starting their coding career. Cheers!!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s