in reply to OO style: Placement of "new"

I personally like code that "reads" like natural language, and I've seen comments by Larry that he does also. I can surely read the following:
my $object = new Thingy; print $log "It works!\n" if $object->is_valid();
However, the alternative just doesn't read as nicely:
my $object = Thingy->new; if ($obj->is_valid()) { $log->print("It works!\n"); }
I do C++, but that's not why I prefer the "new class()" form. It just sounds more like the spoken word. Heck, if I were to slavishly follow C++ syntax, I'd never use the followup 'if' form.

Replies are listed 'Best First'.
Re: Re: OO style: Placement of "new"
by chromatic (Archbishop) on Apr 08, 2003 at 04:36 UTC

    This is not completely indirect object syntax:

    print $log "It works!\n" if $object->is_valid();

    You would instead write:

    print $log "It works!\n" if is_valid $object;

    Your second snippet would likewise be:

    $log->print( "It works!\n" ) if $obj->is_valid();

    I fail to see how that is less appealing.