Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2015-11-27 04:07 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (717 votes), past polls