I had the pleasant opportunity to meet and talk with Dick Hardt of ActiveState on
the Perl Geek Cruise. One of the points he made that I found interesting
was that one of Perl5's failings was that it used a different syntax
(->) for object method calls than other languages. He felt that since
so many languages use a dot for this purpose, Perl was harder to use
because you couldn't just copy example code and use it in your program.
Of course, the code he was talking about was OLE Automation code under
Windows, where you see examples for (for instance) Visual Basic. That
is, assume you had the following VB example code: Set WordObj = CreateObject("Word.Basic")
WordObj.FileNew
WordObj.EditClear
Perl5 requires you to write something like: use OLE;
my $wordObj = OLE->CreateObject("Word.Basic");
$wordObj->FileNew;
$wordObj->EditClear;
This seemed to me at the time like a niche concern, and one that could
be easily taken care of by a reasonable editor (I could make a "paste as
Perl5" macro easily in Vim), or a bit of programming. After all, who's
in such a hurry to make a program that they can't stop and think about
what they just pasted in? But I thought it was an interesting point.
Then somewhat later, I was reading David Simmons' posts on
comp.lang.smalltalk about the great work he was doing on the Smallscript
product (essentially a version of Smalltalk, but with lots of language
improvements). Smallscript runs on the Microsoft .NET platform.
David also mentioned that he'd added the dot syntax, for much the same
reason (copying of example code). Recall that Smalltalk normally would
use something like this:
| wordObj |
wordObj := OLE createObject: 'Word.Basic'.
wordObj fileNew; editClear.
Now I see that Perl6 wants to start using the dot instead of the arrow
(and change concatenation to the tilde (~)).
Apparently, the idea that people have to be able to paste OLE example
code into their programs directly has taken root among a fair
number of smart people in the Perl community and elsewhere. While I have
no particular preference one way or the other with respect to the
proposed Perl6 syntax, I do think that it's curious that this belief is
so prevalent. It may be something Microsoft is promoting, or it may have
come from observation of users in the field.
What bothers me about the belief is that the language designers are
attempting to facilitate cargo-cult programming by doing this. Perhaps
they feel that their languages won't compete well with other languages
that use dots (as I recall, Python, Java, C++ (refs), VB, and Ruby all
use dots for method calls). Perhaps they want to extend the reach of
their languages into the ranks of the VB macro/spreadsheet community.
I don't know. But it seems to me that changing language syntax to match
Visual Basic should be low on people's priority lists.
Re: Dots and cargo-cult programming
by HyperZonk (Friar) on Jul 14, 2001 at 21:48 UTC
|
While convenience in porting code might be a factor to take
into consideration, I have to agree that I do not think it
a strong enough reason to change the current syntax of Perl.
Particularly, I have trouble with the attempt to justify such
a change so that Perl will be more compatible with products
from a company that is trying to destroy Perl.
It is true that implementing dot notation will also make
Perl more compatible with other languages, but when one is
porting code, there are always things that need to be changed.
If we make Perl so much like other languages that it becomes
difficult to distinguish them, then what is the argument for
having different languages anyway?
Another consideration is that this will make backwards
compatibility with earlier perls troublesome. I personally
dislike anything that prevents backwards compatibility. When
a change becomes necessary that creates problems with backwards
compatibility, it is my opinion that the changes necessary
should be relatively trivial. The concatenation operator is
not, IMO, such a trivial change.
I say, let's keep Perl the unique language that it is. Particularly
if, in doing so, we can avoid the appearance of pandering to
those who would destroy it.
Update: per jepri's remarks - I am glad that
there will be a compat mechanism; that certainly resolves
most of my concerns about it. And, I have to agree that
making Perl more accessible to the greater programming
community is a good thing ... still ...
($perl{characteristics} eq 'unique') ? $perl{charm}++ : $perl{charm}+=
+0;
Still IMO, of course. | [reply] [d/l] |
Re: Dots and cargo-cult programming
by petdance (Parson) on Jul 15, 2001 at 00:11 UTC
|
Last month, when I heard Damian Conway talk about stuff coming up in Perl 6, there was much crabbiness from the crowd (or at least one member of the crowd as he discussed the dot operator, but apparently Larry's reasons are pretty much what you said:
Perhaps they feel that their languages won't compete well with other languages that use dots.
Perhaps they want to extend the reach of their languages into the ranks of the VB macro/spreadsheet community.
Larry wants Perl to carry forward, and apparently feels that the arrow is some sort of barrier to entry, and that people are afraid of Perl because of the "nonstandard" way of calling methods. The Visual Basic thing is seen as a huge potential "market" for Perl.
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>
| [reply] |
|
Yeah, I don't like the dot. Here's why:
When I first started with Perl, I had only used the dot occassionally in
C and Javascript. When it came time to learn Perl's arrow, it was
relatively easy: whereas a dot suggests termination, both as period and (US)
decimal, the arrow suggests action, i.e. $object->does_something. This
is the basic reason I hate the dot. Essentially, it throws off the
natural-language written text parser in my head, in a way that is
diametrically opposed to its normal use. (Is there any modern written human
language out there that does not use the period as the default mark for
terminating utterances? Has anyone involved with human-computer
interaction/usability testing ever examined the usability of the semantics
assigned to semicolons, brackets and other "line noise" ascii in different
computer languages? Besides the ongoing sniping over white space vs.
brackets?)
But now, thanks to Java, VB, and other languages,
the dot is the Dominant Programming Convention, and we, the valiant hold-out
programmers who know better, are doomed. Doomed! Doomed, I say! Or should
that be
$we = $I.say("Doomed!" x3);
Damian assured me that the Grand Poobah's
mind is set, and our fate is sealed. And he cajoled me that it wouldn't be
so bad, getting used to using dots instead of arrows; that he had been
against it, tried it, and after a while it was no big deal. He convinced
me, reluctantly, because ultimately that line of code above isn't so bad.
He also gave me this really yummy blue pill.
Plus, I wouldn't call this "cargo cult programming". That's about
propagating ignorance. This seems to me to be a matter of a concession to
convention, when the convention's hold reaches a critical mass and when the
convention is suboptimal but not abhorrent. And I definitely wouldn't go
that far.
Anyway, I'm actually much more concerned about =~ vs ~= right now. Dot
vs. arrow is a nuisance, but that's potentially lethal, and at the
least I hope it's dealt with intelligently by perl6's warnings.
-- Frag. | [reply] [d/l] |
|
I wouldn't call this "cargo cult programming"
The point of the original poster wasn't that the dot
was cargo cult programming, but that it encouraged
people to cut 'n' paste VB code into Perl programs, because
there was no translation of the -> to a .
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>
| [reply] |
|
|
| [reply] |
|
|
|
Not to be pedantic, but where I come from (c++) -> *is* the standard way to call functions that live inside an object that you have a pointer to, which is pretty much the only way I ever use it in perl too. (blessed ref to an object)
'The fickle fascination of and Everlasting God'
- Billy Corgan, The Smashing Pumpkins
| [reply] |
|
| [reply] |
|
|
|
Well I'm glad somebody pointed this out.
It isn't to emulate Java, VB or SmallTalk so much as to
make the code cleaner and easier to parse. Admittedly I'm
attached to the existing arrow operator but I can get used
to using a dot instead.
There are more important battles to fight. That's such a minor one.
| [reply] |
Re: Dots and cargo-cult programming
by jepri (Parson) on Jul 14, 2001 at 22:01 UTC
|
I don't know that we are necessarily changing to suit VB. What I am sure of is that at first glance, I couldn't tell what the smalltalk code does, but I could tell what the VB stuff did. Ditto when I first started Perl, I had no idea what the arrow did, even though I knew what the dots were in VB and Delphi.
Changing to suit the whims of the greater programming community is wrong, but standing firm on small issues is inflexible. I like the -> operator, I think it's neat, but I guess it's time for it to go.
And this is Perl. We've been promised a backwards compatibility layer, so your code isn't going to become obselete over night.
____________________
Jeremy
I didn't believe in evil until I dated it. | [reply] [d/l] |
Re: Dots and cargo-cult programming
by nysus (Parson) on Jul 15, 2001 at 01:26 UTC
|
I just want to say that this territorial outlook toward random symbols is very interesting to me. I wonder: why do programmers, a highly intelligent group of abstract thinkers, become so emotionally attached to a language? Maybe it's because we invest so much time and mental energy---maybe even our very souls---into a language that we actually end up bonding with it!
What's also interesting is to see a tool become politicized which follows into my line of thinking that everything is political. If you're not on a deserted island, you will never escape the world of politics.
My point: none. Just wanted to share my observations. (OK, OK, my hidden political agenda is that I wouldn't mind picking up some XP! :)
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks
| [reply] |
|
As I said, I really don't care one way or the other what Perl6 does, though I'd rather see a syntax that would be less confusing (and some of the changes in Perl6 will help there).I suspect that I'll have trouble with confusing ~= and =~ (especially because Smalltalk uses ~= for "not equal"). If I'm still using Perl by the time Perl6 comes out.
I just thought it was curious that people thought that the copy/paste thing was important enough that they'd let it influence language syntax.
| [reply] |
Re: Dots and cargo-cult programming
by joefission (Monk) on Jul 15, 2001 at 02:50 UTC
|
I've got a slightly different take on the . vs -> syntax grumblings. I have Win32 System Administration background. I was told by someone I deeply respected, that I should learn Perl if I wanted to be a "real sys admin" (curiously he didn't mention the OS...too easy a target, I guess). There are quite a few tools out there that use VB and VBScript for NT Admins. I laughed at people who used VB because, well, it was BASIC (yeah, just a tad naive). However, quite a few books and people use VB for examples on how to script NT administration tasks. One of these books is ADSI ASP Programmer's Reference(1998,wrox, Steven Hahn). I wanted to know more about ADSI and this book had lots of info, even with it being VB-centric. I figured I could port it to Win32::OLE. I was wrong. I didn't want to learn VB so I could learn how to do it in Perl. So this book doesn't even have the spine cracked, because I found other Perl modules aside from OLE to keep me busy. I'm very embarrassed to say that I had no idea that . meant -> until it was brought up in the Perl6 discussions. I guess I can go back, break open that book, and translate the . to ->. If Perl6 uses the . syntax, it might make it easier for people like me to read and learn from other code. Even if it is VB. | [reply] |
|
That understanding will help you, but there will be other differences. For instance, this.that = 2 in VB would be $this->{that} = 2 in Perl. But something like a method call would be this->DoSomething.
Using Win32::OLE isn't as straightforward as you might want it to be. The biggest things to look out for is that when you're setting properties, you're going to be using a hash, and there are other times when you're going to be using lists. For example..
This is some DB code that uses ADO..
#!/usr/bin/perl -w
use strict;
use Win32::OLE;
my $strCon = "Provider=SQLOLEDB; Data Source=XXXXX; Initial Catalog=SM
+S; "
. "User ID=XXXXX; Password=XXXXX";
my $strSql = "SELECT System_DATA.Name0, datediff(dd, LastUpdateDate, g
+etdate())"
. " 'age' FROM SoftwareInventoryStatus INNER JOIN System_DATA on "
. "System_Data.MachineID = SoftwareInventoryStatus.ClientID WHERE
+ "
. "(datediff(dd, LastUpdateDate, getdate()) > 30)" ;
my $objCon = new Win32::OLE("ADODB.Connection");
my $objRecordset = new Win32::OLE("ADODB.Recordset");
$objCon->{'ConnectionString'} = $strCon;
$objCon->Open;
$objRecordset->Open($strSql, $objCon);
while (not $objRecordset->{'EOF'}) {
print $objRecordset->{'Name0'}{'Value'}, "\t";
print $objRecordset->{'age'}{'Value'}, "\n";
$objRecordset->MoveNext;
}
$objRecordset->Close;
$objCon->Close;
and someting similar in VB (sorry, this below is from some ASP a customer asked me to put together. Above is something I use. They don't perform the same task, but you should be able to see what mirrors what.
Option Explicit
Dim objConnection, objRecordset, strSQL, Name
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.ConnectionString = "Provider=SQLOLEDB; Data Source=XXXX
+; Initial Catalog=SMS; User ID=XXXX; Password=XXXX"
objConnection.Open
Set objRecordset = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT Name0, MachineID FROM System_DATA WHERE MachineID >=
+ 0 ORDER BY Name0"
objRecordset.Open strSQL, objConnection
and what was a little confusing to figure out is that in VB, You can refrence the "Name0" field as
objRecordset("Name0")
but in Perl it's
$objRecordset->{'Name0'}{'Value'}
I personally prefer Perl, but with things like Win32::OLE it's a lot of poke and hope to figure out just how you have to access properties and methods. | [reply] [d/l] [select] |
Re: Dots and cargo-cult programming
by PsionicMan (Beadle) on Jul 15, 2001 at 05:06 UTC
|
I write very little object based code. This being the case, I don't really have a bias on this issue (most code i have right now will port fine).
That being said, I'd much rather use . than ->. Why? It's soooo much easier to type. I mean, really... reach all the way up to the hyphen, then all the way down (and holding shift) for the greaterthan (don't know the real name). Maybe I'm a weak typist, but it annoys the hell outa me.
Just my $.02.
--Psi print(pack("h*","e4f64702566756e60236c6f637560247f602265696e676021602075627c602861636b65627e2")."\n"); | [reply] [d/l] |
|
< >
Common: <less/greater than>; bra/ket; l/r angle; l/r angle bracket; l/
+r broket. Rare: from/{into, towards}; read from/write to; suck/blow;
+comes-from/gozinta; in/out; crunch/zap (all from UNIX); tic/tac; [ang
+le/right angle].
In INTERCAL, it's called the "right angle".
—John
| [reply] [d/l] |
|
A poll conducted among poets had established "waka" as the proper
pronunciation for the angle-bracket characters < and >, though some
poets held out for "norkies."
The text of the poem follows:
<>!*''#
^"`$$-
!*=@$_
%*<>~#4
&[]../
|{,, SYSTEM HALTED
The poem can only be appreciated by reading it aloud, to wit:
Waka waka bang splat tick tick hash,
Caret quote back-tick dollar dollar dash,
Bang splat equal at dollar under-score,
Percent splat waka waka tilde number four,
Ampersand bracket bracket dot dot slash,
Vertical-bar curly-bracket comma comma CRASH.
So, I've called < and > "waka" ever since (to the confusion/amusement of all around me) :-)
Russ
Brainbench 'Most Valuable Professional' for Perl | [reply] [d/l] |
Why not spaces instead of dots?
by bikeNomad (Priest) on Jul 15, 2001 at 23:55 UTC
|
Actually, it would make for more readable code if Perl6 made it so that:
$obj a b c(d,e) f
meant the same as Perl5's
$obj->a->b->c(d,e)->f
or the proposed
$obj.a.b.c(d,e).f
I hope that perl6 drops the confusing bareword notation for functions (as opposed to method calls), though. Having a b c d mean the same as a(b(c(d()))) causes you to have to suddenly start reading from right to left to track the order of program execution, even though the rest of Perl is left-to-right. | [reply] [d/l] [select] |
Re: Dots and cargo-cult programming
by schmoe (Beadle) on Jul 16, 2001 at 15:40 UTC
|
These small differences in syntax are what originally made perl4 so damn easy for anyone to pick up. HTML and Perl allowed everyone and their kid brother to build a zillion web sites in several years, ActiveState did not. It's actually a tiny issue that's only annoying because it seems so bass-ackwards to me. If I liked VisualBasic I'd be a senior VB developer by now, and I suspect you would too. Who's clamoring for VisualPerl?? Buehler? Buehler? Anyone?
This is not a multi-part message in MIME format. | [reply] |
(redmist) Re: Dots and cargo-cult programming
by redmist (Deacon) on Jul 18, 2001 at 00:36 UTC
|
One Perlish issue (that frag brought up) in respect to Perl5 method call syntax is that an arrow has the semantic meaning of action. In the case of $foo->bar;, $foo is performing the action bar. I think that using the dot for method calls will lead to a less semanticly meaningful model.
Of course, with this issue, there comes the question of how valuable or important is it to have similar constructs across different languages? Does it add or detract from a given language?
redmist
Silicon Cowboy
| [reply] [d/l] [select] |
Re: Dots and cargo-cult programming
by RatArsed (Monk) on Jul 18, 2001 at 15:46 UTC
|
Why blaim VB? why not blaim consistancy with Java, Delphi, C, C++ et al?
I'm from a strong C/++ background, and find no issue with doing object->method() et al -- let's face it, most C++ code, you only ever have pointers to objects if you want to do anything non trivial.
Regarding the digression on using . for string concatination, I believe through the mists of my memory that at some point duing my studies at Essex University that it comes from some branch of mathematics (which is essentially where all programming originates). I forget which branch and also whether this is just my memory eludin me -- If I remember, I shall check my notes this evening.
--
RatArsed | [reply] |
|
|