3 ms·
> Sure, you could write that algorithm as three nested list comprehensions, but does that accomplish anything other than showing off? Ask different programmers
by lmm 3y ago
> Sure, you could write that algorithm as three nested list comprehensions, but does that accomplish anything other than showing off?
Ask different programmers this and you'll get different answers. One group will say that the list comprehensions reduces ceremony and makes the essential business logic clear, and writing out a loop longhand would serve no purpose other than showing off your knowledge of implementation trivia. Another group would say that writing the code without using list comprehensions makes it simpler, and the other group is just showing off their knowledge of language features.
"Make it simpler" advice is rarely actionable and usually just makes the debates more contentious. https://m50d.github.io/2018/12/11/people-who-disagree https://m50d.github.io/2018/12/11/people-who-disagree
- yen223 3y agoOne of the annoying things about "code simplicity" is that it is a subjective trait. Whether a piece of code is simple to understand depends very heavily on what the reader is used to, and that's not something that the writer of the code has much control over.
- zakirullin 3y ago"Code simplicity" is indeed too abstract. "Cognitive load", however, is more tangible thing to grasp. https://github.com/zakirullin/cognitive-load https://github.com/zakirullin/cognitive-load
- lmm 3y agoThat has pretty much the same problem. Assembly programs have low "cognitive load" by that definition, but few would say that assembly programs are simpler.
- zakirullin 3y agoI wouldn't say so. When you're on assembly programs, you hold things like "register values" in your head as well as other low-level things. It's not only about abstractions and language features.
- YetAnotherNick 3y agoThere are much lower number of register values compared to number of variables any half complicated code has.
- whstl 3y agoAssembly uses more than registers. And unlike registers and memory addresses, you don't really have to juggle regular variables in your head unless the program has a lot of unnecessary mutability, or really bad variable names.
- ZoomZoomZoom 3y agox64 has 16 general-purpose registers. "Much lower" starts somewhere around a half. I say, touching 32 variables in a given scope is not "half complicated", it's sabotage.
- zakirullin 3y ago> number of variables any half complicated code has. It is not about sheer number of variables some code has. It's about how many variables we have to fit in our head in order to understand some flow or calculation.
- whstl 3y agoNot really, assembly has much more cognitive load. Try reading more than a trivial chunk of assembly and you'll see you can get overwhelmed pretty quickly by the amount of information you have to remember. You have to memorize code paths, which register or address has what, offsets of structures, juggle registers.