10 Tips For Clean Code | Michael Toppa
Sep 22, 2017
Here are the 10 tips by Michael Toppa from his talk at Wordcamp US, 2016.
1. Programmers spend most of the time reading code.
We like to think we spend our time power typing, but we actually spend most of our time staring into the abyss. - Douglas Crockford
2. YOU are responsible for the quality of your code.
Act like professionals. You don’t go to the doctor and say, “I am in a hurry. No need to wash your hands. Just go go go!” Adhere to the professional standards.
3. Use meaningful names.
4. Write code that expresses intent.
5. Comments are often lies waiting to happen.
Code should speak for itself whenever possible.
Code updates don’t often include updating the comments. So comments may become misleading.
6. Leave the code better than you found it.
7. Single responsibility principle.
method: does one thing, does it well, does it only.
class: cohesiveness, are most of the methods using most of the properties?
8. Write tests.
9. Independent architecture.
The software architecture should be independent of the framework it is going to be used with. E.g. a wordpress plugin should be designed such that it can be used independently with minimal changes.
10. Practice, practice, practice.
Learn new techniques when the client is not paying you. Do code kata.