3 ms·
> Which versions force your eyes to do less jumping around? Maybe I'm weird but the author's first examples are easier to read. Having labels is good when ther
by athenot 10y ago
> Which versions force your eyes to do less jumping around?
Maybe I'm weird but the author's first examples are easier to read. Having labels is good when there is a non-trivial nested mess, but nothing comes for free. When the idiom is well-understood, being overly explicit ends up with more noise. In the first examples, I'm looking at 1 paragraph of code and understand what's going on. In the supposedly improved examples, labels force a mental dereferencing and a jump to different code paragraphs. Sometimes I don't want to scroll throughout the file (or lookup references) to understand something that's logically part of the same unit of processing.
Of course if the lamdas end up doing a lot of work then the overall structure gets lost and a label would be the right thing to do. But code is no exception to the rule "write for your audience". In this case, the audience is the compiler and humans which are versed in the idioms and style of that environment.
- ams6110 10y agoAgree entirely. My eyes are jumping around most on his last, "preferred" version.
- philsnow 10y agoThe labeled forms give my brain a chunk of code, with a name, to compartmentalize / internalize. In the nested forms, I have to either chunk it on the fly (every time I need to read it) or not chunk it and make my eyes do a bunch of work. Code that comes later in a single code base will usually copy the patterns that are already established in that code base. (Assuming the starting patterns are decent, this is as it should be.) If you add one more level of fun nesting or something like that, the labeled examples become even clearer. Since it's entirely likely that new code will copy the existing pattern, I prefer code shapes that will grow cleanly.