I love indirect object notation

kappa on 2010-06-02T13:54:29

I am fond of indirect object notation.

It's the my $inst = new Class::Class arg => 42; thing.

It's beautiful and I've never faced any unsolvable problems with it. All arguments against it basically sum up to it being too hard to parse properly. As if we got computers not for this exactly reason — to do hard things for the sake of beauty (which is a special case of order).

One example of bad things happening was presented in a post by Matt Trout. Well, not convincing, if I am allowed a slightly offensive quote from Strugatsky brothers here. Do not use it when it causes problems and this particular case seems to be hard to debug due to poor error reporting from perl interpreter only. If indirect.pm DOES detect these cases, why perl cannot? Probably because it's too late to change this behaviour in Perl 5. Well, I shut up and return to work.


Error reporting is not enough

zby on 2010-06-02T20:13:02

because it could end not with a syntax error but instead with a well defined but unexpected behaviour. The important thing is that the possibility that the perl parser treats Two::two { (foo => 'bar', baz => 'quux') } as an indirect call is not something that comes to the mind of the programmer. What that indirect call does, whether it is an error or not, is always something unexpected.

Been bitten by this many times

cjfields on 2010-06-09T15:33:14

I work heavily with an old OO system where this syntax bit us several times with some very hard-to-diagnose bugs. Switching project-wide to direct syntax fixed a ton of these.

Yes, you can probably use this if you are careful and know what you are doing, but the problem I found is many devs don't know about the problems with it (or willingly ignore it). To me it's just easier to code defensively in this case and stick with direct syntax.