Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Re: Re: where do you put your subs

by ignatz (Vicar)
on Mar 08, 2002 at 13:53 UTC ( #150314=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: where do you put your subs
in thread where do you put your subs

Not when dealing with objects.

my $paco = $foo->bar;
Is this a scalar or a call to a class method with no paramaters? Let's sift through the code to find out, oh joy!

My main point is that subroutines are doing the majority of the work in a block of code. () at the end makes them stick out. Hi there! Being almost blind, I love having these handy little pointers in the code that I'm looking at. The fact that it the rule of law in other languages means that my subconsious is naturally drawn to them. Just because you can do something different than other languages doesn't mean that you have to.

update: I just knew that I would put my foot in my mouth when I start talking about OO perl. ++ to both responses. (I still hate it bareword methods. :-P)


Comment on Re: Re: Re: Re: where do you put your subs
Re: Re: Re: Re: Re: where do you put your subs
by demerphq (Chancellor) on Mar 08, 2002 at 13:59 UTC
    my $paco = $foo->bar;
    Is this a scalar or a call to a class method with no paramaters? Let's sift through the code to find out, oh joy!

    It is and can _only_ be a method call. If it were anything (or rather the only other thing that I can think that you could mean) else it would be written as

    my $snafu=$foo->{bar};
    The placement of the subs at the top of a package does _not_ prevent you from using the parens style, whereas placing at the bottom _does_ prevent you from using the bareword style. Whereas the placment of subs has an indirect effect on error rates. Thus there is still no reason not to employ best practice.

    Yves / DeMerphq
    --
    When to use Prototypes?
    Advanced Sorting - GRT - Guttman Rosler Transform

Re: Re: Re: Re: Re: where do you put your subs
by Juerd (Abbot) on Mar 08, 2002 at 14:04 UTC
    my $paco = $foo->bar;
    Is this a scalar or a call to a class method with no paramaters? Let's sift through the code to find out, oh joy!

    Let's sift indeed:

    my $paco =
    Ah, we're creating a lexically scoped scalar called $paco
    $foo
    It has something to do with another scalar, called $foo
    ->
    The arrow indicates we're either going to dereference, or have method call.
    bar
    No [] or {}, so it's a method call. Neato, we're using objects!
    But we can't see whether $foo is a scalar holding a blessed reference (better known as object) or a scalar holding a package name. That's only because it's called $foo, because a good name would tell us.

    And do you really put package names in scalars and then use those to call class methods? It's ugly, just like using soft references.

    44696420796F7520732F2F2F65206F
    7220756E7061636B3F202F6D736720
    6D6521203A29202D2D204A75657264
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://150314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2013-05-25 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (519 votes), past polls