Forwarding you to alemil.com

23 guidelines for writing readable code - Alemil: Gamedev blog

Reading someone else's code can be quite confusing. Hours can go on issues that should have been fixed in minutes. In this article, I would like to share some advice on how to write code that will be easier to understand and maintain. Before we get started, please take notice this is not a guide about writing "clean code". People tend to understand different things by this term, some like it to be easily extendable and generic, some prefer to abstract the implementation and provide just configuration and there are some who just like to see a subjectively beautiful code. This guide focuses on readable code, by that I mean a piece of code that communicates the necessary information to other programmers as efficiently as possible. Below are 23 guides to help you write more readable code, this is a lengthy article so feel free to jump to parts that interests you: 1. Identify that you have a problem before creating the solution 2. Pick the right tool for the job. 3. Simplicity is king. 4. Your functions, classes, and components should have a well-defined purpose. 5. Naming is hard, but it's important. 6. Do not duplicate code. 7. Remove dead code, do not leave it commented. 8. Constant values should be in static constants or enums. 9. Prefer internal functions over custom solutions. 10. Use language specific guidelines. 11. Avoid creating multiple blocks of code nested in one another. 12. Its not about the least number of lines. 13. Learn design patterns and when not to use them. 14. Split your classes to data holders and data manipulators. 15. Fix issues at their roots. 16. Hidden trap of abstractions. 17. Rules of the world are not the rules of your application. 18. Type your variables if you can, even if you dont have to. 19. Write tests. 20. Use static code analysis tools. 21. Human code reviews. 22. Comments. 23. Documentation. Conclusion.