Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Perl "new" command

by nemesdani (Friar)
on Mar 01, 2012 at 07:27 UTC ( #957119=note: print w/replies, xml ) Need Help??

in reply to Perl "new" command

Since the title of the node is "Perl "new" command", we should also add that in Perl the constructor doesn't have to be named "new". It's just a common thing to do, which helps people understand each other's code better.

Replies are listed 'Best First'.
Re^2: Perl "new" command
by Erez (Priest) on Mar 01, 2012 at 09:26 UTC

    n Perl the constructor doesn't have to be named "new"

    In Perl no, but OO frameworks like Moose and its derivatives have adopted this convention and use "new" for object instantiation.

    Principle of Least Astonishment: Any language that doesn’t occasionally surprise the novice will pay for it by continually surprising the expert

Re^2: Perl "new" command
by JavaFan (Canon) on Mar 01, 2012 at 10:00 UTC
    Actually, constructors cannot be named new. The name of the constructor in Perl is called bless.

    Unless you make an XS function called new which reimplements bless.

      I thought a constructor is any routine that calls the bless operator.
        That would be a silly and confusing definition. If you had:
        sub foo { my $x = bless [], "X"; my $y = bless {}, "Y"; ... return 1; }
        Is that a double constructor? Half a constructor?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://957119]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2018-02-25 04:51 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.