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!
|
|---|