Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

kappa (294)

  (email not shown publicly)

Perl Hacker since 1998. Lives in Moscow, Russia.

Journal of kappa (294)

Wednesday June 02, 2010
08:54 AM

I love indirect object notation

[ #40374 ]

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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.
  • 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.