DEV Community

Discussion on: What do you do when you can't write something in a clean way?

Collapse
 
mattkocaj profile image
matt kocaj

If it can't be "clean", being verbose, more lines than you might prefer but readable is the answer! Readability should always be the default position.

Readable means "intention revealing". We spend most of our time reading code, not writing it. So code that is named well, easy to follow and reason about is "readable". It doesn't have to be "clean" with the most slick interfaces, or latest language syntax and "cool" helpers. It just needs to be readable.

An example might be a couple of substr uses in a single line instead of a regex. Sure the regex is more terse - but it's not as easy to grok for most folks. There's a greater cognitive load with things like regex, lambda expressions and other syntactic sugar.