in reply to Re^5: I hate nested loops
in thread I hate nested loops

No, it means I need only one idiom, regardless whether the RHS is a literal, a more complex expression, or whether I initialize one or more structures. Using one idiom instead of more improves readability, IMO.

It's like having just one type of umbrella in the boot of your car instead of a whole bunch, each of them suitable as protection against a single type of rain.

Replies are listed 'Best First'.
Re^7: I hate nested loops
by BrowserUk (Patriarch) on Aug 11, 2011 at 08:34 UTC
    only one idiom

    But that is the absolute antithesis of what Perl (and all VHL languages) are all about.

    We could (and for a while did) program using just a single flow control idiom: goto. If reducing the number of idioms we used was a virtue, we'd still perform the initialisation like this:

    my @e = 'a'..'z'; my @n = 1..10; my $href; my $ie = 0; OUTER: my $e = $e[ $ie ]; my $in = 0; INNER: my $n = $n[ $in ]; $href->{ $e }{ $n } = 1; $in = $in + 1; if( $in < @n ) { goto INNER; } $ie = $ie + 1; if( $ie < @e ) { goto OUTER; }

    We don't any more for very good reasons.

    You've pointed out many times that the C-style for loop is far more flexible than the perlish for loop, but we have both and most people prefer the latter for most uses. (Albeit that some use it when it is less appropriate.)

    Using one idiom instead of more improves readability, IMO

    IMO, if you think about it a little more, you'll change your mind.

    By definition, the more general an idiom, the more situations it is applicable in. Which, also by definition, means the more closely you need to inspect it to understand which of those situations it is being used for in this case.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.