ok, so every shop has style guidelines, and some of those style preferences differ from my own, and I'm perfectly fine with that - if the team wants 4 spaces but I'm a two-spacer, or if they don't care that they have some lines that are 172 characters, fine. but this one just doesn't make any sense to me:
all method/function calls end in () for
'clarity'
now, for function calls like this
my $foo = bar();
bar()
might get shuffled in larger codebases so just using the bareword might fail to compile someday.my $foo = $obj->bar;
my $foo = $obj->bar();
$obj->bar
$obj->bar()
()
is required and tricky, likemy $foo = $cv->();
()
add clarity to a method call? what else could you possibly expect ->bar
to represent?$obj->bar
$obj->{bar}
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
geoff on 2005-08-23T15:02:39
yeah, like I care about other languages...
nice of you to notice the php to perl migration strategy we've been covertly implementing, though;) Re:Other Languages
shiflett on 2005-08-23T15:42:26
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/
:-)
Re:just easier to read
geoff on 2005-08-23T15:41:46
ugh... it's chaining where I find them the most superfluousjust feels much more idiomatic to me thanmy $val = Foo->new->attribute->format;but ok, you're a reasonable guy, so I'll give inmy $val = Foo->new()->attribute()->format();:) Re:just easier to read
perrin on 2005-08-23T15:53:31
Imagine a mixed-case like this:
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.
A sub is a property is a sub. What about when using the
sub value : lvalue {
my $this = shift;
$this->{VALUE};
};
Would you put the parens here:
my $value = $self->name();
but not here:
$self->name = 'Chris';
or leave it
$self->name() = 'Chris';
Re:What about :lvalue?
Dom2 on 2005-08-23T19:19:22
Using:lvalue is bad because you lose encapsulation. -Dom
Re:What about :lvalue?
jk2addict on 2005-08-23T21:38:59
Hell I'd never use it. I hate.
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:
Aristotle on 2005-08-26T18:43:30
Unless you return a tied object that validates the value it gets assigned. Which is obviously a huge overhead.
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