Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Just another Perl shrine
 
PerlMonks  

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.


Comment on Re: Handling braces with methods without arguments
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994041]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-04-20 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls