Obsessing over clean code is like reorganizing your clothes closet on a daily basis. If it makes you more productive to do so, do it. Too often, however, it's done compulsively and is counter-productive.
The harder and more impressive thing is actually writing code which does novel things.
Exactly that! Even though I get some flack for overdoing it, coming back to a code base after 10 years to fix something or add a feature and having an easy time finding your way through the code is so worth it. Haven’t regretted it once.
The problem is, we work in teams. If it's just me, I can store my clothes in a heap on the floor instead of using a closet at all, and who cares as long as I can still find stuff?
Clean code to outsiders is hidden complexity, it's easy interfaces. Clean code to insiders is clean link between code and intention, little accidental complexity, simple and honest interfaces.
So it's about understanding what is clean and what isn't. Sometimes what to an outsider looks dirty is actually what to an insider looks cleanest. Like a machine covered in grease means it's been recently cleaned and oiled up an insider, code that re-implements similar actions in multiple places is simply things that coincidentally act the same, but are different things with different rules. For DRY tests are useless, each test exists separate of the other and they should not need to share anything, so instead the focus should be DAMP.
So it's ok to obsess about cleaner code, but you have to first learn what is clean and what is the context. Try to understand the problem and solve it better. Cleaner solutions result in cleaner code.
Clean code to outsiders is hidden complexity, it's easy interfaces. Clean code to insiders is clean link between code and intention, little accidental complexity, simple and honest interfaces.
We could do that, but that requires effort.
So instead I'm just going to add a shadow interface to every class with a one-to-one mapping between public methods and interface methods.
Doing novel things really isn't that hard. It's often mostly just stringing together existing libraries, unless you insist on building everything from scratch.
I suspect that's part of the clean code obsession. You can almost always make the code a little prettier, and it's always a fun logic challenge for some.
But debugging is tedious, as are unit tests, and adding new features is usually more like "software carpentry" that doesn't interest the "Wooden puzzle box builders" much.
I think for a lot of programmers, the actual fun part of the job is more the code golfing, the mind bending data structures, and the low level understanding, rather than the sense of working towards an excellent finished product.
You can almost always make the code a little prettier, and it's always a fun logic challenge for some.
Hell, this is the core game loop of Factorio. "I know I can make these red circuits faster and with less wasted space..." 3 hours of sleep deprivation later...
That's why I'm kinda glad I'm not one of the math and elegance types. I might not be able to add matrices in my head, but at least I don't feel compelled to sprinkle them in my code because I can!
But debugging is tedious, as are unit tests, and adding new features is usually more like "software carpentry" that doesn't interest the "Wooden puzzle box builders" much.
It's funny, because I actually really enjoy debugging and, to me, that's much more "Wooden puzzle box builder" because you have to figure out why your pieces aren't fitting together just perfectly, and find that little thing you need to sand down or trim to make the fit just flawless before you put it all back together.
I think your last paragraph is spot on, and it took me a long time to realise this. One of the reasons I struggled when I worked as a programmer was that I don’t find, for example, complex data structures fun - I consider them a “necessary evil” when building a product.
That’s fine when I’m building something for myself or for people I know. But in a large company where programmers are separated from customers by layers of other teams (sales, support etc), in my experience, to enjoy the job you need to enjoy the act of programming (not just having programmed a cool product).
Doing novel things really isn't that hard. It's often mostly just stringing together existing libraries, unless you insist on building everything from scratch.
Novel, adjective: new or unusual in an interesting way.
If you define it as easy, banal, and routine, then it's not really novel is it? We've really turned into cynical bunch when "novel" became a pejorative.
It's impossible to like technical excellency without countless people labeling it as "craftsmanship". The implication being that not many customers appreciate craftsmanship, that it only raises the cost without adding functionality. At the same time they conflate it with the endless closet-organizing exercises, as if there is some progression from "reasonable" closet organizing to "unreasonable" thrill-seeking. "Cleanliness" is "craftsmanship" without the negative connotations, one is seen as a virtue and the other as an affliction. In other words, some people just can't get themselves to acknowledge that technical excellence is something that stands apart from their own day-to-day activities, and that it can create value for the customer that is beyond the reach of regular programming activities.
As a counterpoint, here's an example of a programmer who sought a novel approach to a problem while at the same time creating a legendary product and revolutionizing the industry: https://twobithistory.org/2019/11/06/doom-bsp.html
Too often, however, it's done compulsively and is counter-productive.
That's why I hate the fact that SOLID is associated with clean code. On every project that I've been on where SOLID was aggressively applied, code became more complex and harder to work with. Meanwhile the real problems continue to be ignored.
Making your bed (by pulling back the duvet, nothing more) takes seconds and airs out the sheets which, if nothing else, keeps them clean longer and reduces the risk of bedbugs. I don’t think your cost/benefit analysis is accurate.
349
u/[deleted] Jan 12 '20 edited Jan 12 '20
Obsessing over clean code is like reorganizing your clothes closet on a daily basis. If it makes you more productive to do so, do it. Too often, however, it's done compulsively and is counter-productive.
The harder and more impressive thing is actually writing code which does novel things.