Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Should a constructor ever return undef? (yes)

by tall_man (Parson)
on Jul 11, 2003 at 15:10 UTC ( [id://273397]=note: print w/replies, xml ) Need Help??


in reply to Re: Should a constructor ever return undef? (yes)
in thread Should a constructor ever return undef?

Ok, it looks like the consensus of most of the answers is that returning undef is normal. But I'd still like to make it harder for the unwary programmers to forget to check the return. I'm suggesting to my co-workers that constructors that can return undef be named "fallible_new" instead of just "new". That might be a little obnoxious, but it would help prevent bugs.
  • Comment on Re: Re: Should a constructor ever return undef? (yes)

Replies are listed 'Best First'.
Re^3: Should a constructor ever return undef? (yes)
by adrianh (Chancellor) on Jul 11, 2003 at 18:32 UTC
    Ok, it looks like the consensus of most of the answers is that returning undef is normal.

    Just because something is commonly accepted doesn't mean it's good ;-)

    But I'd still like to make it harder for the unwary programmers to forget to check the return.

    You might want to look at using the Fatal module. You can use this to force an exception to be thrown if undef is returned.

    However, if returning a false value on failure is actually causing problems for you I would strongly consider moving over to an exception throwing style.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found