(jeffa) Re: Noble DOT vs the Allmighty ARROW
by jeffa (Bishop) on May 07, 2002 at 23:16 UTC
|
When i first came to Perl from Java/VB, i didn't like the
arrow operator-> Now i do->
I suppose i'll feel a little uncomfortable at first, using
the dot operator in Perl6, but things change.
So, looks like i am going to have to go ahead and say
bring the dot operator on. Without change, things can
get stale.
As for the underscore for the concatenation operator ...
eduardo said it to me best - "How many times do you
really use it?" Not that much->. :)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] |
|
|
Having spent some time writing a largish program in perl 6 (and then porting it to perl 5 to make sure that the design was sound), I found that one of the persistent mistakes I kept making in my perl 5 code was trying to use . all the time instead of ->.
However, the hardest thing to give up was the given/when syntax, which is just lovely. Being able to use the -> $foo, $bar {...} syntax to make anonymous functions of known arity was rather cool too, if a little more obscure...
| [reply] [d/l] [select] |
|
|
Could you expand on "writing a largish program in perl 6"? How does one go about doing such a thing? I thought p6 was merely in the design stage. Is there a "working" p6 interpreter that we can play with?
-Blake
| [reply] |
|
|
You can still use Conway's switch module in Perl 5. It uses source filters to translate switch/case or given/when structures to Perl 5 structures.
| [reply] |
|
|
|
|
Without change, things can get stale.
True, but that does not mean that you should change things just for the
sake of changing them. That breeds confusion, not progress.
(see also: most Microsoft Office document formats)
Now, I haven't been following perl 6 news at all, so I don't know
why this is being changed. Anyone got a pointer handy
so information about the reasons behind the ->/. thing?
| [reply] |
|
|
I tested my all of my perl code that was handy with this script:
#!/usr/bin/perl -ln
$arrow += () = /->/g;
$period += () = /\./g;
END {
print "arrows occured $arrow times";
print "periods occured $period times";
}
and got these results:
arrows occured 454 times
periods occured 227 times
Now Perl has always been Huffman encoded (things used often should require less work than things done seldomly) so '.' (or some other one character operator) should replace '->'. When they went looking for a replacement they noticed that almost everyone else in the known world was using '.'. There are also other features in Perl 6 that cut down on the number of concats needed. | [reply] [d/l] |
|
|
| [reply] |
Re: Noble DOT vs the Allmighty ARROW
by talexb (Chancellor) on May 08, 2002 at 14:09 UTC
|
My background is C, where the dot refers to an object attribute (or for non-OO folks, a structure element). Hmm. Let me explain better.
typedef struct foo
{
int iNumberOfHands;
char *pszPlayerName;
} PLAYER, *PTR_PLAYER;
PLAYER astrScoundrels[];
PTR_PLAYER pstrThisPlayer;
This code defines a structure in C with two elements, and also defines types for an instance of the structure (PLAYER) and a pointer to a structure (PTR_PLAYER).
The type definitions are used to created an array of players and a pointer to a player. After all that, you use pstrThisPlayer->iNumberOfHands to get to a structure element using a pointer, and astrPlayer[2].iNumberOfHands to get to the same structure element using the structure itself.
Currently in Perl (there, you knew it was coming eventually), we use the arrow to refer to an object's attributes or members like
$Query = new CGI;
$Value = $Query->param('foo'); # method call
In reality, $Query is an object and not a pointer to an object, so we should be using the dot syntax. Therefore, in Perl 6, we will be writing
$Query = new CGI;
$Value = $Query.param('foo'); # method call
This is what C used all along, so going to the dot syntax is more othogonal. Or better. :)
--t. alex
"Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny
ps Good question.
| [reply] [d/l] [select] |
|
|
A quick thought but the dot is hardly unique to C. I wouldnt be suprised to discover it actually comes from ALGOL which (iirc) is higher up in both C and PASCAL's family trees.
Even if it isnt, it certainly has been part of PASCAL, Modula-2, C, C++, JAVA, VB and a whole host of other languages.
OTOH, I dont think ill like doing
my $s=sub{};
$s.();
Hmm, come to think of it what will be the syntax for dereferencing a CODE ref? The above cant be right can it?
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look. | [reply] [d/l] |
|
|
my $anonsub = sub { ... };
$anonsub(@args);
HTH
_________ broquaint | [reply] [d/l] |
Re: Noble DOT vs the Allmighty ARROW
by Dog and Pony (Priest) on May 08, 2002 at 13:51 UTC
|
First off, coming from java OO programming, I definetely prefer the dot notation for this, but I don't really have a problem with the arrow either (anymore, should say). I am pretty sure that the arrow notation comes from C++, which have both. Note that I am not especially good at C++ (it was a long time ago) but I think this is how it works (in C++):
Method invokation on an object is done with object.method(), while method invokation on an object reference is done with object->method(). So the arrow operator also dereferences the object, and then invokes the method on that object.
Since all(?) objects in perl are references to something (often a hash), this syntax suddenly makes a lot more sense.
It is the same syntax you use when you dereference several things in perl, one of the most notable is when you invoke a reference to a sub with $code_ref->(), but also constructs like $hash_ref->{'key'}.
Since I started thinking like that, it made a lot more sense, since java has no pointers or references at all. As long as this notation type is somewhat consequent, I'm happy to use both. (Pedantic note: technically, everything in java is pointers/references, but the language hides this fact - for you nitpicks out there ;-) ).
People that are a lot better than me at this are very welcome to correct and fill in blanks. :)
Update: ariels says I am confusing references and pointers in C++ - and I am sure it is so. (Thanks for the heads up). I am not very good at it anyways... I thought it might be a reasonable explanation to why perl has the arrow notation, and not the dot as so many others. Then again, maybe not. :) Just don't try to apply any of the above to real life coding or anything. :)
Update 2: talexb sets things straight as well. Now, I remember some more... :)
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue. | [reply] [d/l] [select] |
Re: Noble DOT vs the Allmighty ARROW
by Albannach (Monsignor) on May 08, 2002 at 17:55 UTC
|
Ok, let me take this opportunity to start a movement for a new standard character, the arrow. We'll get it added to all 8-bit character sets that don't already have one, have it included as a standard on all keyboards, and then nobody will be able to complain about the number of bytes or keystrokes... and it will just plain look better in all fonts if it isn't cobbled together from other characters.
If APL can do it, why not Perl?
--
I'd like to be able to assign to an luser
I hope you all realise that I'm joking... I've got too many causes on the burners already right now ;-)
| [reply] |
Re: Noble DOT vs the Allmighty ARROW
by cjf (Parson) on May 08, 2002 at 12:05 UTC
|
I prefer the dot. It's one less character to type and is more consistant with other languages I use.
Other than the complications that arise from not being able to use . in other places, there isn't much to discuss. Syntax isn't nearly as important as most people make it out to be.
| [reply] |
Re: Noble DOT vs the Allmighty ARROW
by lachoy (Parson) on May 08, 2002 at 00:12 UTC
|
It's just syntax, I'm sure that anyone getting into a tizzy now will either get over it or move on.
Chris
M-x auto-bs-mode
| [reply] |
| A reply falls below the community's threshold of quality. You may see it by logging in. |