DEV Community

Discussion on: The term "clean code" is misleading - this is my take

Collapse
 
lexlohr profile image
Alex Lohr

I too think 'clean code' is ambiguous and confusing. I prefer 'code describing the problem it solves' and while this is not as concise as 'clean code', it's much better to convey the idea.

When you start your career as a developer, your aim is to write code that runs without errors. With more experience, your aim extends to code explaining itself in terms of the solution it provides. And lastly, you want the code to describe the problem it solves.

As a simple example, styling comes to mind (which is woefully underrated and thus usually not written well). Let's consider a price tag:

<!-- beginner -->
<b style="background: yellow">$ 4.70</b>

<!-- advanced -->
<span class="bg-yellow bold" aria-label="USD 4.70">$ 4.70</span>

<!-- expert -->
<style>.price-tag { font-weight: bold; background-color: yellow; }</style>
<data class="price-tag"><currency aria-label="USD">$</currency> 4.70</data>
Enter fullscreen mode Exit fullscreen mode

You might ask: but what if I compose my styles in a component with tailwind like the advanced developer? Use a descriptive variable name to hold the different class names.

Why describing the problem and not the solution? Because knowledge of the problem helps understanding the solution more than knowing the solution.