Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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.


Comment on Re: Perl "new" command
Re^2: Perl "new" command
by Erez (Curate) 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
Node Status?
node history
Node Type: note [id://957119]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-07-11 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls