HACKER Q&A
📣 thescribbblr

Tips for Writing Clean Code


I am a mid level programmer but still I face issue with writing clean code.


  👤 aristofun Accepted Answer ✓
Tip #1 — don't try to write clean code. Try to solve the task with best quality possible.

The quality of outcome (how reliable, performant and stable to edge cases your feature is).

Clean code will eventually and naturally come. Don't waste your energy starting from wrong side.


👤 Communitivity
Good code tells a story. You should be able to read the code like English, starting with your inputs, and see how your inputs are transformed/processed into your outputs.

Good code is just simple enough. You can, through refactoring make code overly simple (think dozens of 1 line functions, where 3 5-12 line functions do the trick). A function is a scene though - no more, no less. Don't try to stuff a chapter or a novel into one function as that isn't simple at all.

Good code is commented with comments that explain and add meaning to the code, rather than repeating what is obvious from the code itself.