Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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]
[thezip]: So, we have a small deployment coming up soon for a project. What is the general name for the project management documentation that details the tasks and schedules/ sequences for the execution of the deployment?
[thezip]: Deployment checklist?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-02-23 17:47 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (350 votes). Check out past polls.