Ingo Blechschmidt skribis 2006-01-05 18:32 (+0100):
> Juerd wrote:
> > Ingo Blechschmidt skribis 2005-12-25 17:37 (+0100):
> >> I disagree about binding only being a language thing:
> > I fail to see how your example code illustrates your disagreement.
> >>         return 42
> >>             if (my $short := $long_parameter_name) == $specialcase;
> I inferred that you think/thought that binding should/can't be used in
> expressions

No, that's not what I meant.

A "language thing" means it's mostly relevant for the way you write
something as a result of the feature. In case of binding, the most used
application is aliasing: getting a second way to address the same
variable -- probably because the alias is less typing.

> >>     push @foo, (my $head := pop @grtz);
> > A bit better style, but I'd still recommend against it.
> Consider:
>     my @sites = < abc.org def.org ghi.org >;
>     loop {
>         push @sites, (my $site := shift @sites);
>         check_for_updates($sites);
>         sleep ...;
>     }

    my $site := shift @sites;
    push @sites, $site;
    check_for_updates($sites);

Although in Perl 6 I'd be much tempted to do:

    given shift @sites {
        push @sites, $_;
        check_for_updates($_);
    }

Because $_ is visually easy to recognise, making it immediately obvious
that it's the same thing in both lines.

(This is also my main argument against any style that ALWAYS provides an
explicit loop variable: $_ is easy to spot, and thus is more than just
easy to type.)

> Consider a perhaps more usual example:
>     while(...) {
>         process($tasks[$i++]);
>         if(...) { $i--   }  # redo the last task
>         if(...) { $i = 0 }  # redo all tasks
>         if(...) { $i++   }  # skip next task
>     }

As ugly. In fact, using an index is the ugliest part of your example.
Still, separately, $i++ in the process() instruction is bad style IMO.
Incrementing $i is important for program flow, and should be its own
statement, directly following indentation. 

Also, if you remove process() here, the entire program is broken,
because there was an important but easy to overlook subexpression was in
it.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Reply via email to