in reply to Re^2: I hate nested loops
in thread I hate nested loops
The double foreach loop is a whole lot easier to read though ;-)
I don't know. Maybe for a newbie, but I don't find it so. I have no trouble reading slice syntax -- I use it a lot -- and find the way it extends from 1D to 2D and so on, very natural and readable.
More importantly, I prefer the single line syntax to the multi-line because it makes it very clear that this is simply initialising the HoHs to a bunch of 1s, and nothing more. I like that I can read as "Initialise the 2D hash to 1s". There is little opportunity to misread the intent and screw it up by injecting extra stuff in the loops.
It would be even nicer if I could do (something like):
my %netifaces{ @eths }{ @nets } = (1) x *;
My point I guess is that this initialisation (whilst possibly important), is essentially a trival part of the overall algorithm, and having it as a single line gives it a weight commensurate with that.
Conversely, spreading it out over 5 lines with named iterators makes it take on a weight that makes it seem far more significant than it is in the overall scheme of things.
Ie. This is but a single step in the algorithm, and having it as a single line in the source code makes that very clear. Which I like, and feel is helpful when reading the overall algorithm.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: I hate nested loops
by JavaFan (Canon) on Aug 11, 2011 at 05:46 UTC | |
by BrowserUk (Patriarch) on Aug 11, 2011 at 06:15 UTC | |
by JavaFan (Canon) on Aug 11, 2011 at 08:07 UTC | |
by BrowserUk (Patriarch) on Aug 11, 2011 at 08:34 UTC | |
|
Re^4: I hate nested loops
by rastoboy (Monk) on Aug 10, 2011 at 22:46 UTC |