my $foo = bar();
I think it makes sense, since the definition of bar() might get shuffled in larger codebases so just using the bareword might fail to compile someday.
for method calls, however, I'm completely unconvinced. I don't see how
my $foo = $obj->bar;
is any less clear than
my $foo = $obj->bar();
but perl has lots of little easter eggs that even the best of us don't know, so I ask: in this case can
$obj->bar
ever mean anything different than
$obj->bar()
? and I don't mean for cases where you need to pass in arguments() is required and tricky, like
my $foo = $cv->();
I mean, in all seriousness, exactly how does () add clarity to a method call? what else could you possibly expect ->bar to represent?
maybe it's the difference between
$obj->bar
and
$obj->{bar}
? if so, I don't buy it
Other Languages (Score:1)
Maybe they are taking other languages into consideration. For example, to someone with a PHP background, this looks like a property:
my $foo = $obj->bar;
This looks like a method:
my $foo = $obj->bar();
I think the parentheses universally indicate a function or method, so that might be what they mean by clarity.
Re:Other Languages (Score:2)
Re:Other Languages (Score:1)
I'll see your PHP to Perl migration strategy and raise you a Perl to PHP migration strategy:
http://search.cpan.org/dist/PHP-Interpreter/ [cpan.org]
:-)
just easier to read (Score:1)
Re:just easier to read (Score:2)
Re:just easier to read (Score:1)
my $val = Foo->new->{attribute}->format->{id};
It can get confusing quickly, especially when people do that horrible "return yourself" method chaining that SOAP-Lite uses. I know I'm in the minority on this though. I just don't think there's any advantage to leaving them off, and it makes your code less consistent.
What about :lvalue? (Score:1)
A sub is a property is a sub. What about when using the :lvalue attributes; as evil as they are?
Would you put the parens here:
but not here:
or leave it
Re:What about :lvalue? (Score:2)
-Dom
Re:What about :lvalue? (Score:1)
However, I have seen 3rd party modules that use it internally, so calling those 3rd party functions will fall under the formatting policy above.
Re: (Score:1)
The only rationale for consistent guidelines is... (Score:2)
In this case, that may make the code more greppable. So you don't have "->foobar" results when you grep for "->foo" for example. (Note that I and my shop both disagree with this particular guideline :)
One of the nice things about -method()... (Score:1)
Oh wait, I'm dreaming about the PPI automanipulatification of Perl::Style (or perhaps you'd call it Perl::MyWay)...
In any case I REALLY need to get around to getting that written.