Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: new() function: incorrect?

by fmerges (Chaplain)
on Nov 12, 2008 at 09:53 UTC ( #723093=note: print w/replies, xml ) Need Help??

in reply to new() function: incorrect?


Well in itself it's nothing wrong with it, it creates an object...

A couple of thinks can be mentioned like, there are people that don't like to have the possibility to instantiate a new object by calling an object see ref ||. Other things are more a style question... you don't need to have the bless and the return on two different lines. Maybe they didn't like the command => undef without the leading ',' to avoid errors when you add something and forget the comma...

Another thing could be that you could skip the whole constructor even by using some sort of module, like Class::Accessor for example. The 'use warnings' pragma could be there, even commented it looks good...

But it looks more that they evaluated overall your coding practices by this example... maybe to much BPP, who knows... I would rather look on a longer piece of code, with some algorithm, see if you know also to write tests, etc, etc.


fmerges at

Replies are listed 'Best First'.
Re^2: new() function: incorrect?
by fmerges (Chaplain) on Nov 12, 2008 at 10:08 UTC


    Actually the worst "constructor" I've seen so far came from someone who considered himself an expert and it was like this:

    sub new{ my $self = shift; my $dbh = shift; $self->{dbh} = $dbh; return $self; }

    On top of that also calls like the following from the caller:


    And it was not in one module, it was in the whole layer that deals with the DB from a web application running under mod_perl! You can imagine for yourself what sort of strange creatures were also lurking around...

    Update: Added emphasis on the worst...


    fmerges at
      That won't even run. It dies of strictures. Definitely qualifies for worst.


        As you can imagine, there was no use of 'strict' and 'warnings' pragma nowhere, tests, what are tests? Don't want to mention more stuff as I'll get angry ;-)


        fmerges at

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://723093]
[Discipulus]: he eh latinos superstitious peoples..
[Discipulus]: here at my $work fuc**ing bas**ds proposed to everyone 20 free month of pay to leave
[Discipulus]: I expect a cut of 20% of emplyoment nexet year..
[choroba]: 20 months? :-o

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2018-05-23 20:52 GMT
Find Nodes?
    Voting Booth?