Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by demerphq (Chancellor)
on Mar 08, 2002 at 13:35 UTC ( [id://150308]=note: print w/replies, xml ) Need Help??


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

This doesnt make sense. Scalars are prefixed by the $ sigil wheras methods are not. Just exactly which scalars do you mean?

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

Replies are listed 'Best First'.
Re: Re: Re: Re: where do you put your subs
by ignatz (Vicar) on Mar 08, 2002 at 13:53 UTC
    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)

      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

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://150308]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-25 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found