> “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
It clicked and instantly disabused me of the notion that smart people write code that's any smarter than the minimum required to solve the problem at hand.
It's a brilliant quote, though.
Mostly down to task decomposition.
Some of the stuff in compiler debugging? Just 2x clever, because you have to hold it all in your head at once to solve it.
Circuit debugging or data transformation debugging? You can break it down into smaller pieces, then methodically (and laboriously) worth through those pieces.
Comments being required are also another smell that the code doesn't explain itself. I know this is said so often it's a cliche, but it really is true.
I think both of these things point back to the same problem: out of control data structures.
There's a real danger that comments aren't updated when code is, particularly if 3rd parties make those changes. This is one of the corners where there will never be a single answer which is right in all circumstances.
So much this. If it took you everything you learned over the last week + an epiphany to come up with a bit of code, how is someone scanning through supposed to understand it?
Or, in example with hilariously apropos incomplete post-hoc comments, 0x5F3759DF https://en.m.wikipedia.org/wiki/Fast_inverse_square_root#Ove...
That problem exists because no one denies pull requests or rejects code that has outdated comments.
As an example, given:
const sales = [ {month: "Jan", day: 1, total: 120 }, ... ]
You could determine, say, the highest sales day of a given month as follows: const highestSalesDayByMonth = _.chain(sales)
.groupBy("month")
.mapValues((salesForMonth) => _.maxBy(salesForMonth, "total"))
.mapValues("total")
.value()
// highestSalesDayByMonth = { Jan: 140, Feb: 90, ... }
Naturally, minimizing the complexity of the iteratee functions and carefully naming of their arguments is very important to ease debuggability.Concision can be used for emphasis as verbosity can be used to obscure.
> Instead, I find myself having to re-write ultra-dense blobs of code in order to debug or even simply understand what's going on.
Is this problem because their method is inherently nee complex or is it due to lack of familiarity?
Perhaps they debug that code differently then you do and it's incompatible with your previous mental model?
I believe, definitely, that they are quite intelligent people that know a lot about the language or maths, but definitely they are not usually making the smartest choice, because you should use “languages” in order for the people to understand you.
So you can call those: “50 cent expressions”
They help no one but their ego…
Typically more concise code takes advantage of core language abstractions.
It is actually simpler unless you are unfamilar with core language abstractions, but I'd argue that's a you problem.
He was a much beloved professor.