develooper Front page | perl.perl5.porters | Postings from June 2013

Re: [PATCH] use dots - allow '.' instead of '->' everywhere andconcat with '~'

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
June 14, 2013 12:58
Subject:
Re: [PATCH] use dots - allow '.' instead of '->' everywhere andconcat with '~'
Message ID:
20130614125811.GB24511@cancer.codesimply.com

dots.pm was initially proposed because code using dots instead of arrows can
make a given piece of code easier to read and write.  I think this is the best
argument for it.  I put a few code documents through a naive transformation
from arrows to dots, and I tended to find it about the same for skimming, and
sometimes a bit easier.  Sometimes things were confusing or unpleasant, but I'm
willing to say that on the whole, it looked a bit nicer.

There are other tradeoffs, though.  Chip and I had an exchange about whether
this is an improvement of the Huffman coding of Perl.  I don't think it is.
It's true that "->" is more keystrokes than ".", but in every piece of code,
one will have another toggle to keep in mind: dots or arrows, here?  That is:
there is an increase in the total syntactical complexity of the language, even
if the change in any one document is an even swap in/out of two operators.

It isn't exactly that, though.  The pre-existing unary tilde means that some
statements will parse differently when there's a tilde instead of a dot.  It
makes sense, if you think about it, but it's another way in which dots.pm is
introducing syntactical complexity[*].

Others (but not Chip) have said that dots will help people new to Perl.  I
think this is wrong.  It will be a hindrance.  Unless dots become the standard,
new Perl programmers will definitely encounter arrows, and maybe dots.  They
will need to understand both syntaxes[**].  If they're reading documentation in
one style but writing code in another, they'll need to know how to translate
between the two, which may mean more than just operator substitution.

Then there's the problem of ~=.  It's true that we already have some "the same
but for transposition" operators, like >= and =>.  =~ and ~= are less visually
distinctive, though, and at any rate, I'm not sure "well, we already had one
problem" is a great reason to allow for another.

So, this sums up my feelings: starting from scratch, dot might be better, but
from where we are now, offering a choice of either is worse.

Breno wrote:
> Are we really afraid that a 'dots' pragma will be massively adopted?
> Because if we are, then I feel this is even more reason to do it.

Adding something that we think is going to be popularly adopted is only a good
idea if we think that the thing is a good idea to begin with.  If it's going to
lead to problems, but be widely adopted, it will lead to widespread problems.
That's an argument for not doing it at all.

Pluggable operators, in theory, would get us the ability to have "dotty style"
code, along with many other benefits.  Please note that I have considered it,
and I don't look at this as obstruction through "the perfect is the enemy of
the good," because I don't think that dotty style is a good.  It's just
something that would be possible if built atop a generic-use system for
operators.

Initially, I said I was leaning toward applying this because of popular
acclaim.  It would have been more accurate to say that I wanted to avoid a lot
of angry email.  I don't want to make decisions based on fear, because then
whoever screams loudest wins.

I don't think dots.pm would be good for perl, and am not going to ship it in
5.20.



[*] There are other weird unexplored things here:
  use dots; $x = [ 1, 2, 3 ]; say "$x.[0]";           # doesn't work (yet?)

  use dots; use overload '""' => sub {3};             # my complication had a
  $x = bless [ 1, 2, 3 ]; say("321" =~ /\A$x.[1]\z/); # bit of a complication

[**] Incidentally, it's not just programmers who will need to learn the new
style, either.  Quite a few programs will, as well.  PPI, syntax highlighters,
perltidy, and probably other tools.  There's a bunch of work needed to make
this branch of the syntax "first class" in programmer tools.  I mention this
not as an argument against new syntax, but to temper the notion that this patch
alone would be enough for many programmers.

-- 
rjbs


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