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 ]

schwern (1528)

  (email not shown publicly)
AOL IM: MichaelSchwern (Add Buddy, Send Message)

Schwern can destroy CPAN at his whim.

Journal of schwern (1528)

Wednesday April 18, 2007
11:37 AM

Indirect object syntax, I hate you.

[ #33022 ]

I hate indirect object syntax. I think its an unnecessary confusion just to support new Class. It doesn't really work for anything else as English sentence structure is subject then verb. Even new Class @args falls apart.

That's style, and style can be endlessly argued. This can't.

  use Test::More tests => 1;
  sub Foo::bar { 23 }
  ok Foo->isa("bar")
  Can't locate object method "ok" via package "Foo" at -e line 1.

Grammatical ambiguity to support new Class. GRAH! -> is the second highest precedence operator and should take precedence over indirect object syntax. Worse, the meaning of ok Foo->isa("bar") changes whether or not the Foo symbol table has entries at compile time.

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.
  • A couple years ago I tracked down a bug in DBIx::Librarian [] where database handles were hanging around and causing trouble. Granted, the context I was using it in wasn't straight forward, but here's what the fix turned out to be:

    sub DESTROY {
        my ($self) = @_;

    -   disconnect $self if $self->is_connected;
    +   $self->disconnect if $self->is_connected;

    The author turned around a new release really fast, but it's a reminder to me to always use the direct syntax.

  • I've never used nor liked indirect object syntax, it is much less clear, and makes even less sense in non-english languages.

    @JAPH = qw(Hacker Perl Another Just);
    print reverse @JAPH;
  • My favorite is reading code at Perl Monks that mixes different constructor invocation styles.

    Are you up for patching the documentation of the most egregious offenders? I can think of a few places in the Perl core that need re-education.

  • ## The problem is that you didn't use enough of it!

    use Test::More tests => 1;

    sub Foo::bar { 23 }
    ok can Foo "bar"
  • As an aside for anyone reading this who didn't know it, you can fix this with a unary plus:

    ok +Foo->isa("bar");

    But yet, indirect object syntax is very, very annoying.

  • I hate ...

        new Object(...); ... but for reasons I don't really understand I love ...

        throw Exception(...);

  • I never use indirect syntax with one exception: exceptions:

    throw My::Exception('Boom!');

    I should really get our of that habit. Then the game would be complete.