Here are some of my thoughts on programming best practices to improve productivity.
YAGNI: “You Ain’t Gonna Need It”. Don’t write code that you think you might need in the future but don’t need yet. This is coding for imaginary future use cases and the code could become dead code or need rewriting because the future use case could turn out to work differently from how you imagined it.
Comments & Console Logs: When comments are used they should be used to explain why the code is there, not what it’s doing as that can be read in the code itself. Blocks of commented code shouldn’t exist in productions releases. This is also true for testing console log statements which should not make it to production releases.
Testing: Test all changes. Only if there is a very good reason should code be left untested. Lack of time is not a good reason and can end up costing more time. Possible good reasons include: genuinely un-testable (in any meaningful way), impossible to hit in practice, or covered elsewhere in a test. Code without tests is a liability.
Code is the Enemy: Code can go wrong and it needs maintenance, so try to write less code, delete code, and don’t write code you don’t need.
Write Defensively: Always think about what can go wrong, what will happen on invalid input, and what might fail, this will help you catch many bugs before they happen.
DRY: “Don’t Repeat Yourself”. If the same code is being repeated multiple times consider putting it in a reusable function. This is more important in production files and not as important in test files, keeping code and what could go wrong in the production environment to a minimum.
Correct VS Speed: Make code correct first and fast second. The top priority is to write code that works and has been confirmed with test. The second priority is the performance and speed of the code (within reason, provided it is not excessively slow code which will cause issues).
Standard Format: It is good to have a standard format (use of indentation, spaces, blank lines, comments) all developers on a project work to, in order to help improve fast readability and help reduce development time.
Original Article Posted On: https://andycorby.com/some-programming-best-practices-for-productivity/