Later I realized that the fact that it was easy to change was what made it good and the changes I wanted to make to it would probably just make it more complicated.
That's the danger; good code is easy to change so it will easily get rewritten until it's not easy to change anymore.
It's exactly same as arguing you should not educate your workers. Cause they might leave. So you get only the least knowledgeable ones.
Software solves business problems. Code that meets its requirements needs to be left alone. Developers just changing code because they feel like it need some coaching. They're wasting everybody's time for reasons that amount to "I like it My Way".
So, with normally performing developers, the only code that changes is the code that needs to change. Good or bad only has an influence on the cost of a change.
Nothing to do with "just changing code because they feel like it".
There is nothing that makes good code more or less likely to change than bad code.
Sounds like the 'bad currency drives good currency out of circulation' problem. Bad code drives good code out, because good code is easy to understand and change.
I call this the Peter Principle of Programming:
"Code increases in complication to the first level where it is too complicated to understand. It then hovers around this level of complexity as developers fear to touch it, pecking away here and there to add needed features."
I will highlight though that I have worked with people that choose the path of least resistance regardless of complexity of the code that would need to be changed. It's as if they refuse to read code.
Template meta programming is an entirely separate, incredibly complex, programming language distinct from c++. The only people I have ever seen use it in production are exceptionally skilled programmers. Everyone else flees and cowers. If they try to change it it will not compile. So why is this good? Because it only allows the framework to be extended in the ways intended by the original designer. Anyone wanting to update this unholy beast will be a master programmer who’s investing significant effort. That implies the updates will be good.
Good code is easy to change. Great code is near impossible to change, but easy to extend.
In such a code base, it quickly becomes understood that if changes are required to “framework Doom” in order to achieve a new feature, the time budget will need to be large. It’s built in tech-debt prevention.
Premature generalization is a well known problem and a never-ending source of complexity. I lost count of the times I had to push back on PRs of clueless developers who felt the need to generalize one-liners that pop up twice in the whole project, and for that their proposal was to add a strategy pattern, ultimate replacing two expressions with three classes.
https://nigeltao.github.io/blog/2021/json-with-commas-commen...
In other words, if it's easy for the CPU to read, it's probably going to be easy for a human too. They both stumble a little on indirection and jumping around.
The other advantage of simple (macro-level, and not "one line functions" micro-level simplicity) code is that it also tends to have fewer bugs, and what bugs do appear, are also easier to find and fix.
Now abstraction also have a cost that needs to be kept under control. (Some have zero costs, some have compile-time costs, some have different level of run-time costs) And of course, not every abstraction is a good one: Sometimes it can even be counter productive to hide details if these details are simpler than the abstraction itself.
In summary, it's all about trade-offs and not over-doing it.
Many abstractions are also conventions, just look at the js/react world. There is redux stores, mobx stores, hooks, class-based components, signals. All different abstractions with various performance and readability concerns. Someone used to one of them would say the others are not readable or maintainable. So maybe we can choose the more performant abstractions and teach them, so it becomes institutional knowledge.
CPU likes if/else and loops just as much as it like its gotos. If/else and loops are just conditional jump (with a comparison done before the jump), and gotos are uncoditional jumps. Both are very much machine code constructs, that's why they're in C (which is basically a syntactic sugar over assembly).
Function calls are slightly more involved, but basically also very, very low level.
if (!condition)
goto else_;
// some code
goto endif;
else_:
// the else block
endif:
// More code
Same for loop. That's what we mean by "goto considered harmful".Here are my thoughts in a bit more detail from a previous thread: https://news.ycombinator.com/item?id=35061151
If we were closer to the model where a program would read its fixed inputs (for the run) and it would be specialized in place for the input using partial evaluation, with profile feedback for data accesses to help transforming the internal data representations to optimize storage requirement and cache access patterns, we would be much more motivated to specify many things abstractly enough to give machine representations of the code and data more freedoms.
I don't recommend it to juniors anymore because it hasn't aged well and is for my taste hyperbolic in its promises.
IMHO clean code also is more focused on code implementing "business logic" than "systems programming" for example (probably a bit tricky to actually define what the difference is between these too).
For those wondering, "How to Design Programs"
It's more up to the point instead of going into dogmatic diatribe
It's more evidence based (giving examples, etc)
Go for this one and Bob's your uncle! (or maybe it stops being your uncle, I guess)
What a great book. I second this and add my own "The Pragmatic Programmer: 20th anniversary edition"
That, and "Team Geek", in term of relationship with codes and teammates.
edit: oh, and also it's hard to avoid people checking in and/or editing the generated code
https://www.destroyallsoftware.com/screencasts/catalog/funct...
https://www.destroyallsoftware.com/talks/boundaries
It seems unrelated in the surface, but I feel like they explain the "why" of a software architecture in a much simpler way and without the prescriptive and hand-wavy "trust me" nature of most software architecture books.
I also think some of this... attitude? learning? is what go is trying to activate/take advantage of. Everywhere I've worked has had some monstrously experienced senior dev who could easily crack out a solution to a problem of any difficulty but who refuses to use any abstraction more sophisticated than a for loop.
Go says you don't need anything more sophisticated than a for loop, in fact you can't have anything more sophisticated than a for loop. I guess I'm not there yet but it definitely seems suspicious that the people I know who are most into go are very early in their careers or deeply experienced.
For a junior the answer is more "I'll just use bootstrap and customize as much as needed".
While for a senior it's more in line with "I'll just use bootstrap, but you bet I will be on the designer's ass if they ask to customize stuff where it's not necessary."
There is a reason the mid-level developer wanted to write custom CSS. And the reason is that they didn't have the political capital to make bootstrap alone work in a way that is good for the company.
To be fair, this can be said about any technique. Lots of bad code results from people taking a reasonable principle and applying it religiously rather than judiciously.
You have a ball of highly optimized mud, that quantum collapses if you glance at it too harshly, and we need it to be USB compatible. By Tuesday. Good luck!
So you're actually a clean code proponent.
As is usually the case with such debates, it is a debate of differing definitions masquerading as a debate of differing arguments.
I think plenty of people love clean code. I love programmer efficiency and readability. But there's clean code and "Clean Code". Some of the code examples from Robert C. Martin's Clean Code book are absolutely atrocious. I would be horrified to find anything so unnecessarily abstracted and overcomplicated in my codebase.
Its precisely because I'm all for readability and programmer efficiency that I find the recommendations in "Clean Code" so bizarre and abhorrent.
Surely this depends on the context? If you have a many different classes it tend to lead to cleaner code if you encapsulate the class-specific logic with the class definition rather than intermingled in multiple giant switch statements. In particular you can add new classes without making the rest of the code more complex.
Of course there are cases where a switch is the right choice.
Yes, it depends on the context. In this case the context is the switch statement described in the https://www.computerenhance.com/p/clean-code-horrible-perfor.... Too bad TFA never mentions it explicitly (other than in the title and in the video). Recently it generated a heated discussion around here.
A struct only contains data, however you e.g. can define methods on it or implement traits for it No inheritance.
However it has some other uses, e.g. when you really want to support adding new cases without modifying the code, e.g when doing a library, you need some kind of polymorphism.
So basically - it is not that abstractions/indirections are inherently bad, but they come at a cognitive cost. And it depends on the context if this cost is justifiable.
For me that depends on the context:
* A challenge for an interview? No wonder people try to insert structure as if it were a bigger project.
* A challenge for a contest? Probably not a good solultion for most point systems.
* A challenge for fun on hackerrank or LC? Whatever you feel comfortable with works.
For structuring a larger system, separating data ingestion, data output and algorithm to work on the data, seems like a fairly entry level separation.
I don’t blame the players, but I do wish there was some way to inoculate the herd. Perhaps we need a proper religious tradition. Robes would at least make it fun.
This is a great comment. Quotable even.
OOP was pushed very strongly in the 90s, for example, and people promising to create massive increases in productivity by providing consulting services for "OOP-ifying" code probably made plenty of $$$ off that fad.
I've seen less production code and more discussions on code that focusses on opposite ends.
terrible readability and maintainability with extreme performance.
v/s.
terrible performance with overdone "design" abstractions.
OTOH, I've seen lot of production code that has good enough design, with well done perf and vice verse.
Not much talk about that stuff.
Tying these two together. Clean Code doesn't distinguish between framework code and business logic code. Or more you should write the latter like the former. The problem is writing framework code is hard to do well. It needs to be well thought out, bullet proof, and importantly well documented. That takes a lot of time and effort and running the code under a number of different use cases.
One is better off writing business logic as straight forward and goal directed as possible.
The coding culture around Clean Code seems to put a lot of effort into "building frameworks on top of frameworks" without really admitting it, and the "framework-y bits" are intertwined with business logic, like exposed piping in a building. But business logic should look more like Golang instead.
And above a certain size dry works against you because when making changes to component A that requires a slight modification of the behavior or component Q deep in the call stack is so painful because the blast radius is huge. Dry codebases end up slowly accumulating more and more effectively read-only code that makes implementing non-trivial changes require increasing amounts of cleverness until development slows.
I think the more general principle is more to do with code directionality and framework vs library but the motivation to franken-framework your code always seems to be dry.
Even Uncle Bob's examples are not the state of the art in readability: https://qntm.org/clean
And performance of the program vs performance of the developer is a false dichotomy. So many times I've seen a more readable, simpler code turned out to be more efficient as well. You often can have both.