Since the objects have no obvious public method new it makes more sense (to me) to call them in a magical sort of way. I don't see what adding the : to the end of the name does for anything. It certainly doesn't make it clearer. However new Object is pretty standard across many languages while your two examples are not. I would agree with using your second form on everything except new. It reads easier when you say $x is a (=) new Object.
| [reply] |
The colon marks the invocant of an indirect method call, at least if you're passing parameters. I realize you didn't pass parameters, but I recommend getting in the habit of always using the colon or never using indirect notation.
The purpose of requiring the colon is to disambiguate the language. Indirect object notation fails in difficult-to-debug places in Perl 5 and the goal is to avoid that in Perl 6.
The syntax and semantics of other languages don't really apply. This isn't C++ or Java. It's Perl 6. Unlike both languages, new is not a keyword in Perl 5 or Perl 6. It's a method call.
If Dog.new is a burden, consider using an in-place mutator:
my Dog $ralph .= new();
| [reply] [d/l] [select] |
I'll take this opportunity to complain again about the word "invocant". "Invocant" means "invoker" which means "caller". But it's being used to refer to the object, which is not the caller, it's the callee. It is the object, after all, not the subject. In the cultures of certain other, more pure OO languages, the object of a method call is sometimes called the receiver, because calling a method is likened to sending a message. "Invocant" is just wrong, because the object does not call its own method.
I realize that in syntactic constructions like $obj->meth(), the object looks somewhat like it's taking an active role. But it's not.
| [reply] [d/l] [select] |
Any word on why it isn't a keyword? I mean in perl6 you no longer define your own new. So is there a reason new isn't a key word that triggers the contructor? Like I said before, I wouldn't use inderict object notation anywhere else, but in the case of new it hardly feels like a method, and you are acting on a class not an object. I wonder if not making new a keyword is some attempt at leaving the language dynamic.
Update: Thanks for clarification on all points to both chromatic and TimToady
| [reply] |