Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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.

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
Node Status?
node history
Node Type: note [id://957119]
help
Chatterbox?
[stevieb]: it is exceptionally difficult I'm finding to debug a dist that is x-platform, where on each platform you're wrapping a different binary. Trying to co-ordinate a successful test run where tests are extensive is a nightmare, especially when the dist...
[stevieb]: ...you're testing is a test system itself. 10+ documented issues fixed, another half dozen found while fixing the original ones. I'm getting there...
[stevieb]: Then throw in changes to Windows that throws everything you trusted right out the window.
[shmem]: that's why it is called "Windows"

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-03-28 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (342 votes). Check out past polls.