On 10/24/05, Mihai Manuta <[EMAIL PROTECTED]> wrote: > Given the most used practice in the OOP is to return null (or a NullObject) > when you don't have anything to return (and you don't have an error, there > is just nothing there to give back...) it seems only reasonable for other > developers to expect you to do that.
There is a strong school of thought in software engineering that returned values should not be 'unusual', i.e., you should never have to say "if result is not special, then do something with result". That school of thought produces code that is not full of return value checks, but uses either precondition checks or exceptions instead. That school argues that being forced to check return values everywhere in your code makes code hard to read and makes code brittle (a single missing test likely leads to subtle failure or, if you're lucky, an exception). That school never uses "" as a special string return, never uses 0 or -1 as a special numeric return and would never return null when a real object is required. Just remember that a "most used practice" is not necessarily a good practice. I'm actually in agreement with Barney on this (despite him saying he disagrees with me! - I think if he disagrees with Hal then he also disagrees with Vince, not me). Provide a precondition check *if* the situation is 'expected' so code can explicitly test for the expected condition but have the 'get' routine throw an exception if the precondition is not met. -- Sean A Corfield -- http://corfield.org/ Got frameworks? "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). CFCDev is supported by New Atlanta, makers of BlueDragon http://www.newatlanta.com/products/bluedragon/index.cfm An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
