Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Handling braces with methods without arguments

by greengaroo (Hermit)
on Sep 17, 2012 at 13:48 UTC ( #994041=note: print w/replies, xml ) Need Help??

in reply to Handling braces with methods without arguments

I always use the second syntax: $object->method(). The reason is simple. Since I use Moose and MooseX to create my classes, I want to differentiate a call to a common method: $object->method() and a call to an attribute "getter": $object->attribute.

Moose automatically creates a getter-setter method for each read-write attributes. The same method can be call to "set": $object->attribute('new value') or to "get": $object->attribute.

Now let's say the attribute is an object itself, and I want to call one of its own methods: $object->attribute->method() but if I call a method that returns an object based on an argument, I would do: $object->method('arg')->method() or $object->method()->method().

Of course this is just me... I like to have a certain standardization of my syntax because I feel it helps me read my code and I hope it would help others too! It's easier to debug when you know what the programmer intended to do in the first place.

But remember, there is always more then one way to do it! My advice is find the way that suits you the best and be consistent with it!

There are no stupid questions, but there are a lot of inquisitive idiots.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994041]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-06-21 05:15 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.