Hey there 👋 I'm back with another short little post.
There are many articles about this thing we call "clean code". But I feel they lack ...
For further actions, you may consider blocking this person and/or reporting abuse
I’d say clean code refers to the principles of Clean Code. Even if that’s not the intent of whomever uses the phrase it’s the context that surrounds that topic. There’s now a decade+ worth of discussions on top of it so it’s not to say every clean code discussion has to reference a Clean Code chapter, but I dare say it’s crucial to have the awareness of what the words “clean code” originally applied to (whether you agree w. the book’s principles or not) to guide such discussions productively.
Ohh I did not realize the term originally came from the book, good to know! I read the book years back, but thought the term was already established.
at leat you are a honest man. keep on thinking things for your self. but know your meme, in this case books, as well ;-). sapere aude
Keff you wrote this article without know that?!
Yup a little mistake. As I said, I have read the book and have done a bit of research on the subject, but never realized it was originally from the book (or I might've forgotten about it) 😅
For me, clean code means knowing and applying established coding and design principles like "single responsibility", "program against interfaces", "composition over inheritance" , "comment why, not how" "apply formatting", "write unit tests", "avoid global mutable state", etc. I don't think they are "just opinions", but a result from long real-world experience building maintainable software. There are good reasons why such principles exist. Of course they're not "truths" either, but every developer should know why they exist so they can weigh whether to follow them or make an exception.
Thanks for your take, I agree with you.
I don't think they're just opinions, though some could be interpreted as such. Over time I have seen many beginers and younger folks misinterpret the meaning of it, or even more advanced developers writing posts that just scrap the surface and make people think that's all there is too it. The main point I wanted to get across (though I might have failed) is that it's not something that is done immediately or just by using the principles. As you said one must understand why they are used, when to use them and be consistent thoughout the life of the codebase. It takes time, discipline and knowledge.
Thanks for explaining! I've also seen some posts here titled such as "Don't use else-if", such opinion pieces are easily confused with deeper principles that I think of as "clean code". Thanks for your good and thoughtful post!
No worries, glad you liked it! And thanks for your addition.
Yup, those types of posts kinda inspired me to write this post!!
Google's code review guide says this about design:
"Aspects of software design are almost never a pure style issue or just a personal preference. They are based on underlying principles and should be weighed on those principles, not simply by personal opinion. Sometimes there are a few valid options. If the author can demonstrate (either through data or based on solid engineering principles) that several approaches are equally valid, then the reviewer should accept the preference of the author. Otherwise the choice is dictated by standard principles of software design."
I think many of the "clean code" principles are such standard practices and not highly opinionated.
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:
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.
Just use Prettier cuz it makes the code "clean".
True that! ;)
As "Uncle Bob" says, Clean code is
youtu.be/7EmboKQH8lM?t=682
Maybe they mean "clean code = consistency"
Yeah, that's probably the case, though why not just call it "consistent code"?
I generally agree
Great! Can I ask where you differ?