Live data from Hacker News

There’s No Such Thing as Clean Code

steveonstuff.com

61–70 of 395 posts

Re: There’s No Such Thing as Clean Code

#61

There is such a thing as simple code. The job of the engineer is to make complexity simple, even when your target market is other engineers. The complexifiers and verbose Vogons persist heavily today though, as well as project management processes that create an infested myriad of complexity from shallow code to legions of dependencies and asset flipping rather than an effort to be close to the actual standards that…

Absolutely, and I'd say:

> make complexity simple, even when your target market is other engineers

including and especially if the target market is other engineers.

Simplicity though is achieved with additional effort. It almost always requires additional effort to make the implementation simpler while having the same outcome.

It's why my personal motto is "Think more, write less". This, however, is not something that's encouraged in software companies. You are supposed to be sitting there and typing non-stop, that's what they call a "software engineering job".

In fact I never call any code "clean" because the term is vague. All that matters is how simple it is and thus how maintainable and performant, though occasionally the two can contradict each other, but most of the time they don't. Say, a complex caching algorithm can improve performance, so that's an exception. But most of the time simple is a synonym of both maintainable and fast. Can't think of anything else that matters, has real practical consequences and is not just hand waving around "common practices".

Re: There’s No Such Thing as Clean Code

#62
I agree - "clean" or "good" are the same type of keywords like "professional" or "specialist".

I worked in places where code was 100% conformant to the official style guides, but every single change was painfully slow and quite a lot of people complained about working environment. Code was handbook level beautiful though, even if not exactly bug free.

I also worked in feature factory where management was crazy, code was unimaginably inconsistent (same module, multiple files, one file - tabs, other file - spaces, third one - MIXED), but people were mostly chill and happy about pacing and themselves. No one believed in code so it was quite common to double and triple check most of the changes. Environment was very stable due to this.

Eternal dichotomy - code as an art or form of engineering - shows really good here. For some utility, infinite extensibility and minimal code even in exchange for implicitness is cleaner than expressiveness and strictness.

Thus, no code is clean. I could guess Java code isn't clean for Rubyist and likewise. There's a reason we have so many languages available.

Re: There’s No Such Thing as Clean Code

#63
post #29

Clean code is code that does what you expect it to do without many surprises. It is simple, not clever. Effortless to follow. Each part handles one idea at a time, at the same abstraction level. Doesn't force you to mentally juggle many balls at the same time. The code often tells you a story, it communicates how the programmer (author) described the problem, the solutions and the trade-offs. Very similar to writing.…

What you can easily follow though is largely a function of your programming background. An experienced Haskell programmer will have no issue following all kinds of “.” and “$” usages, but one who is not experienced with Haskell, even if they learn what the syntax means, will have trouble following it.

Re: There’s No Such Thing as Clean Code

#64

In my 5th role where I write code, and I have dealt with so many different approaches and definitions of "best practice" that at this point I just roll over to whatever the generally agreed approach is at my current org and mimic it as best as possible. In one organization, I have even had two seniors go back and forth telling me to remove what the other senior told me to put in. The entire process of defining "clean…

Similarly, the existence of so many subjective and unarticulated views on "code correctness" has left me in a place where the only certainty is: there is no certainty.

If your best practices are so great, make a sound business case for them. Uncle Bob did no such thing.

Re: There’s No Such Thing as Clean Code

#65
post #29

Clean code is code that does what you expect it to do without many surprises. It is simple, not clever. Effortless to follow. Each part handles one idea at a time, at the same abstraction level. Doesn't force you to mentally juggle many balls at the same time. The code often tells you a story, it communicates how the programmer (author) described the problem, the solutions and the trade-offs. Very similar to writing.…

“Effortless to follow” is eloquently put.

When I interview candidates during recruiting I often ask the open ended question “what is good code for you” as it gets people talking. There is rarely a wrong answer. Usually, there is a difference in answers between more junior and more senior programmers. More senior candidates focus more on the readability & maintainability, while more junior programmers focus on accuracy, speed, following style-guides etc.

For me “good code” is code that is easy to change. Most things follow from that: easier to understand makes it easier to change. Do 1 thing (SRP), makes it easier to change, etc..

Re: There’s No Such Thing as Clean Code

#66
post #59

The Uncle Bob Martin definition of "clean code" from his book "Clean Code: A Handbook of Agile Software Craftsmanship" is a set of rules that absolutely are not at odds with one another. If you follow them you will end up with code that's really nice to read and easier to maintain, and, most importantly, that you can confidently change. There's a decent summary here - https://gist.github.com/wojteklu/73c6914cc446146b…

Yeah I agree with almost all of these. IMO the most important is “keep it simple”. That is always always my coding North Star and it’s served me well over the many years I’ve been programming.

Re: There’s No Such Thing as Clean Code

#67
> Hopefully I can convince you that you don’t really need clean code, you need _____ code. It’s up to you to fill in that blank with words that describe what your project requires.

The answer to this lies in quality of the final product, which is roughly determined by two opposing forces:

1. How simple is it for a team to make changes and continually meet the quality spec.

2. The velocity at which the team can make those changes to meet the product spec.

Anything apart from these, is down to someone's personal preferences (usually in search of trying to invent a DSL mimicking their favourite language).

Re: There’s No Such Thing as Clean Code

#68
post #59

The Uncle Bob Martin definition of "clean code" from his book "Clean Code: A Handbook of Agile Software Craftsmanship" is a set of rules that absolutely are not at odds with one another. If you follow them you will end up with code that's really nice to read and easier to maintain, and, most importantly, that you can confidently change. There's a decent summary here - https://gist.github.com/wojteklu/73c6914cc446146b…

> is a set of rules that absolutely are not at odds with one another

Yes, if you take them as general guidelines, not dogmatic rules with variable interpretations

The latter is exactly what his fans do

> 2 .Keep it simple stupid

> 2. Prefer polymorphism to if/else or switch/case.

No, not at odds with one another...

Re: There’s No Such Thing as Clean Code

#69
post #66
post #59

The Uncle Bob Martin definition of "clean code" from his book "Clean Code: A Handbook of Agile Software Craftsmanship" is a set of rules that absolutely are not at odds with one another. If you follow them you will end up with code that's really nice to read and easier to maintain, and, most importantly, that you can confidently change. There's a decent summary here - https://gist.github.com/wojteklu/73c6914cc446146b…

Yeah I agree with almost all of these. IMO the most important is “keep it simple”. That is always always my coding North Star and it’s served me well over the many years I’ve been programming.

+1 when I write code I always think about how my reviewers would perceive it before sending it over and I refactor based on that. You should aim to write code that's easy for others to follow.

Re: There’s No Such Thing as Clean Code

#70
post #29

Clean code is code that does what you expect it to do without many surprises. It is simple, not clever. Effortless to follow. Each part handles one idea at a time, at the same abstraction level. Doesn't force you to mentally juggle many balls at the same time. The code often tells you a story, it communicates how the programmer (author) described the problem, the solutions and the trade-offs. Very similar to writing.…

> Perhaps every team need to have a "definition of clean code" for themselves.

All of these concepts are attempts to codify practices that worked really well for specific people in specific circumstances. Like Egg Shen, we take what we want and leave the rest.

Post reply on HN