DEV Community

Discussion on: What makes for readable code?

Collapse
 
sargalias profile image
Spyros Argalias

In short: Care about your work. Try to make your code readable. If you just attempt this as you work you are bound to take more steps towards that direction than if you don't.

Other than that, the answer is: apply standard programming principles.

The rest of the answer would be extremely long as entire books have been written on this topic. However, I would mostly suggest the following.

KISS + principle of least astonishment (things should work as you except) + good naming

  • Code should be as simple as possible. Not smart, no clever tricks. Think of your poor future self or colleague that will have to decipher your code tomorrow.
  • If you have good naming, and you trust your code works, you immediately (mostly) understand what a function does just by reading its name.

Single responsibility principle

Code should do one thing. When in doubt, lean towards extracting or refactoring additional concerns into separate functions with a descriptive name.

There are multiple benefits for this. The basic one is that it keeps functions short and readable.

And much more...

Collapse
 
mx profile image
Maxime Moreau

Care about your work. Exactly! I've worked with different kind of developers, and I've seen that, readable code is coming from developers that like their job, otherwise... "I don't care, my code works".