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.
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.”
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.
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?