DEV Community

Kirill Shestakov
Kirill Shestakov

Posted on

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

When you've been stuck trying to figure out how to write something in a clean and SOLID way, and it's been taking more time that you'd like, what do you do? Do you give up and allow yourself a bit of messiness, or do you do something else to figure it out?

Discussion (1)

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.