Re:An app can be a home-cooked meal
by __MatrixMan__ on Friday January 05, 2024 @01:50PM
(#38882964)
I have my secret perversions as well, so I've got no judgement for you, but I do have to wonder how our editing styles differ if you find that easier to navigate than the equivalent nested for loop.
[ Parent
| on HN ]
for bar_vec in bar_mat:
if bar_vec != []:
for y in bar_vec:
if baz(y):
for x in y:
foo(x)
Seeing it written out here, the example looks nice. In real code with more complexity, it takes longer for me to write it, and it usually takes up a lot more space than this. It bugs me how much space it takes up for something that is one idea in my head (Foo all the baz things in bar_vec).But if there is anyone coming after me, I would write it in this style for their sake, because this style is easier to change.
Re:An app can be a home-cooked meal
by __MatrixMan__ on Saturday January 06, 2024 @03:54AM
(#38889771)
At least in my code, these nested loop thingies are rarely unique. If I have to do it once I probably have to do it many times. If I'm being mindful, I stop repeating myself and just write a generator so that I can invoke it like:
[foo(x) for x in nonempty(bar_mat)]
Mostly this is because I live in fear of ruff's complexity warning, C901.