Does your code smells?

Programming is like my life. Being in the game since i was a little kid, it’s like programming languages are my native languages. Writing good code matters a lot to me.

Being able to write clean code may not seem so important but hazardous situations will occur if you don’t. In the long run, smelly code will make your project maintenance slow. At the end, it is possible, that you abandon it and start over. That is a disaster. And you should not allowed it.

I read a book past week. Reading this book, it was something i had to do loooong time before. Written at 2008, by the father of Good Code, Martin Fowler, it opened my eyes for sure. So many principles i haven’t even thought about it.

Clean Code by Martin Fowler

Clean Code by Martin Fowler

Here’s an example. All this time, i have been writing code, almost 50% of it were comments. I thought this is the way other programmers will understand me.  Martin Fowler flipped it over. “The proper use of comments is to compensate our self’s for our failure to express our self’s.” he said.

Now, i am not going to write a book review. It’s not something i am good at. I will put some of my favorites notes i kept from the book while reading it.

Take a look.

About Clean Code.

Spending time keeping your code clean, is not just cost effective. It’s a matter of survival”

 

“The only way to make the deadline, the only way to go fast is to keep the code as clean as possible.”

 About Functions:

Functions should be small. Even smaller than that. And do only one thing.

 

One level per abstraction in each function.

 

Always prefer exceptions than error codes.

 

Duplication may be the root all evil in software.

About Comments

Comments are bad.

 

The proper use of comments is to compensate our self’s for our failure to express our self’s.

 

Comments are not maintainable.

 

Think twice before you write them.

About Code Formatting

Think of a well written newspaper article. You read it vertically. At the top you expect a headline to tell you what the story is all about and allows you to decide whether is something you want to read. The first paragraph is a synopsis of the whole story. As you continue downwards, the details increase until you have all the dates, the names, etc. We would like source code to be like that.

 

Now this is not just it. This book is a treasure for every programmer. If i got your attention give it a try.

What’s your favorite notes and rules about writing clean code?

 

If you like this article, take a look on a similar i have wrote on @medium and follow me on twitter.

Advertisements

Leave a comment.

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s