Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl "new" command

by nemesdani (Friar)
on Mar 01, 2012 at 07:27 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-19 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found