develooper Front page | perl.perl6.language | Postings from May 2006

Re: A shorter long dot

Thread Previous | Thread Next
From:
Markus Laire
Date:
May 4, 2006 03:56
Subject:
Re: A shorter long dot
Message ID:
67d53e40605040356g96140e0q38bf5f783cd71d79@mail.gmail.com
On 5/1/06, Paul Johnson <paul@pjcj.net> wrote:
> Maybe you all write your code differently to me, but looking through a
> load of my OO code I had trouble finding three method calls in a row to
> any methods on any objects, let alone six calls to the same method name
> on different objects.
>
> If I saw code like
>
>      $xyzzy.foo();
>      $fooz\.foo();
>      $foo\ .foo();
>      $fa\  .foo();
>      $and_a_long_one_I_still_want_to_align\
>            .foo();
>      $etc\ .foo();
>
> I'd probably take that as a pretty strong clue that I should really have
> written
>
>     $_.foo for @things_to_foo;
>
> or something.
>
> I like lining up my code as much as the next programmer, and probably a
> lot more, but I just don't see the need for this syntax which seems
> ugly, confusing and unnecessary.
>
> But then again, as I said, I really don't see the problem that is being
> solved.

This "long-dot" can be used for many things, not just method calls.

IMHO This example from S03 is a lot better:

<quote>
Whitespace is no longer allowed before the opening bracket of an array
or hash accessor. That is:

    %monsters{'cookie'} = Monster.new;  # Valid Perl 6
    %people  {'john'}   = Person.new;   # Not valid Perl 6

One of the several useful side-effects of this restriction is that
parentheses are no longer required around the condition of control
constructs:

    if $value eq $target {
        print "Bullseye!";
    }
    while 0 < $i { $i++ }

It is, however, still possible to align accessors by explicitly using
the long dot syntax:

     %monsters.{'cookie'} = Monster.new;
     %people\ .{'john'}   = Person.new;
     %cats\   .{'fluffy'} = Cat.new;
</quote>

--
Markus Laire

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About