Write Better Code
Paritosh Aug 12 '17
Everyone wants to write better code. I would like to share my approaches and experience to make it easier to write better code. (I am not claiming that I write best code ha ha). But I enjoy the whole process of writing code from scratch.
I always follow Novel's author approach to write code. Novel's author are very imaginative individual who create things out of thin air. here how they achieve it.
- Write down all it's major plot in plain paper.
- They read lots of other novel's,history books, and Fantasy books or lots of books.
- First they write about their main character and then create it's sub character. Write only what is needed to make the story go.
They recite whole novel and modify as along.
Accept critics from other.
Sweet isn't it? It is really good approach.
In the same way if you want to write better code, same habits can be duplicated
Read other Code base : I like reading other code base, it is as important as food. First of all if you can read other code base, your 90% problem maintaining that software is gone. It is also best thing you can do with your career.
Solve one problem at a time : Break down your problem in sub problem, and write only what is most critical piece
Write & Test, Read, Delete and repeat: I would break down in sub tags to explain each.
Write & Test: First you should write code and backing test (unit or integration, Tests are mandatory) don't refactor or try to optimize the code at this point. This is just like writing draft version. The whole goal here to solve one of the problem of the big problem
Read: Once you have done enough and reach at satisfactory point. Try to read with perspective of others.
Delete: This is real fun. "Remember the best code is what which does not need to be deleted" Start removing the code which is not needed , this point you can abstract out dependencies. as you have backing tests you can repeat this steps infinite time. Repeat from Number one again.
Code review is not your review. Give your code base to others , accept critics and repeat from step one
End of the day you will have finest piece of code base.
1) Don't Optimize at first. pre mature Optimization is evil.
2) read a lot of codebase.
Thoughts? Please do share.