Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: new() function: incorrect?

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


in reply to new() function: incorrect?

Hi,

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.

Regards,

fmerges at irc.freenode.net

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

    Hi,

    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:

    $sDB->{dbh}->disconnect;

    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...

    Regards,

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

        Hi,

        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 ;-)

        Regards,

        fmerges at irc.freenode.net

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-26 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found