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

A shorter long dot

Thread Next
April 29, 2006 08:15
A shorter long dot
Message ID:
> 16:50 < audreyt> Juerd: write to p6l and explain the ".." conflict,

The current long dot consists of a dot, then whitespace, and then
another dot. The whitespace is mandatory, which makes the construct at
least three characters long. Tripling the length of an operator, just to
make it alignable, is quite a lot.


    $fooz. .foo();  # doesn't line up, so we have to change the
                    # *previous* line!
    $foo. .foo();   # this lines up again.

So we use:

    $xyzzy. .foo();
    $fooz.  .foo();
    $foo.   .foo();

which is ugly and feels bad. It feels bad, because we're adding much
more whitespace (two character positions in total) than we had to
bridge. And it's a lot of work (many, many keystrokes!) to go back and
change something.

However, the whitespace in between cannot simply be made optional, as
then it would clash with the range operator. As ranges are even more
important than a sane "long dot" solution, the long dot had to change.

Larry indicated that changing the long dot would have to involve
changing the first character. The only feasible solution in the "tiny
glyphs" section was the backtick. I refrain from explaining why that
will widely be considered a bad idea.

Audrey cleverly suggested that changing the second character would also
work, and that has many more glyphs available. So she came up with

> and propose ".:" as a solution,

That's right, dot-colon. There are more glyphs available, but none of
them is nice like this. The basis is in regexes, where a colon means you
commit to have parsed the left side of the colon. That's how the colon
already reads in the indirect object notation, and the colon in
${...} can already be read.

So the actual solution is to make the method call operator not ".", but
".:". Of course, a lone "." still works and is the recommended style for
all simple method calls that don't have to be lined up. You can also
explain it as "." still being the base operator, where ".:" is a special
form. Whatever you like best :)

> and ". :" as an extension, 

Of course, it wouldn't be a solution to the long dot problem if it
didn't allow an arbitrary amount of whitespace in between. 

So, obviously, it does allow lots of whitespace in between. And, of
course, comments. If you really hate your future maintainer, you could
even put some POD in between.

    $foo. :foo();

Or, if you prefer:

    $fooz. :foo();
    $foo.  :foo();

Or, if you actually LIKE the extra whitespace that the current long dot

    $xyzzy. :foo();
    $fooz.  :foo();
    $foo.   :foo();

> and ". +" as an generalization,

Of course, this works nicely with the operators it was inspired by, that
were also inspired by regex postfix operators: ".*", ".+" and ".?". They
can also contain whitespace in our proposal.

The dot-colon fixes another problem too. You couldn't line them up

    $foo.baz();   # makes the ? look like part of the method name

So, now you can:


And an illustration with whitespace in between:

    $fooz. ?foo();
    $fo.   *foo();
> and coexistence/removal of ". ." as a consideration

If we have dot-colon, we could keep the old long dot too. That would
work well with my preference for "..." as the first part of the old long
dot, as three dots stand out much better at the end of a line:


Though that isn't really dependent on the old long dot. It can live
separately. In fact, postfix "..." could be a generic "eat whitespace
and pretend it wasn't there" operator:


    .:bar();  # with normal old long dot, would be :bar(), looking like
              # a pair, not a method call.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About