in reply to Conventions with Passing Objects to Objects

This note is about some bad syntax on your part. I see you're using the new Some::Object syntax. That's bad. Don't. This syntax is really fragile and can cause your program to be parsed very differently depending on compilation order and whether you're writing an OO module yourself. If you switch to the Some::Object->new( ... ) syntax, it will always be unambiguous and the right thing will happen in all cases.

The following snippet highlights the most common case that will go completely wrong.

package Foo; sub new { ... } sub bar { ... = new Some::Object( ... ); # You meant # ... = Some::Object->new( ... ); # but you got # ... = Foo::new( "Some::Object", ... ) }

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: Conventions with Passing Objects to Objects
by zxViperxz (Acolyte) on Jan 13, 2006 at 20:59 UTC
    Thanks for your help, that thread on delegation vs inheritance helps tremendosly and sorts alot of stuff out in my head.

    Also thanks heaps to diotalevi, I've heard about the unambiguity with new before but not understood the problems, that's the first time anyones actually illustrated the problems clearly.

    Looks like I better write a perl script to parse my scripts and correct that syntax. ;)

    Thanks again,
    James.

      B::Deparse will do that. perltidy will do that even better.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊