Click here to Skip to main content
15,884,177 members

Survey Results

Do you return null or an empty object when returning "no result"?   [Edit]

Survey period: 24 Aug 2009 to 31 Aug 2009

If you have a method that is meant to return an object but that method fails to return the object requested (eg. object not found) do you return the equivalent of null, or do you return an empty / default object?

OptionVotes% 
I return null94164.28
I return an empty / default object22415.30
I throw an exception17712.09
I return an error code684.64
Other543.69

View optional text answers (61 answers)


 
GeneralOT: Tuples Pin
Jan Stetka29-Sep-09 13:38
Jan Stetka29-Sep-09 13:38 
Generala good offer to good programmers Pin
quinbee29-Aug-09 1:19
quinbee29-Aug-09 1:19 
GeneralRe: a good offer to good programmers Pin
Cristian Amarie5-Sep-09 21:11
Cristian Amarie5-Sep-09 21:11 
GeneralDo what SQL Server does Pin
Cristian Amarie28-Aug-09 7:20
Cristian Amarie28-Aug-09 7:20 
GeneralRe: Do what SQL Server does Pin
PIEBALDconsult30-Aug-09 4:52
mvePIEBALDconsult30-Aug-09 4:52 
GeneralRe: Do what SQL Server does Pin
Cristian Amarie1-Sep-09 4:01
Cristian Amarie1-Sep-09 4:01 
GeneralRe: Do what SQL Server does Pin
PIEBALDconsult1-Sep-09 4:18
mvePIEBALDconsult1-Sep-09 4:18 
GeneralRe: Do what SQL Server does Pin
Cristian Amarie1-Sep-09 18:30
Cristian Amarie1-Sep-09 18:30 
GeneralOne of my solutions (long post) Pin
Adam Maras27-Aug-09 20:51
Adam Maras27-Aug-09 20:51 
GeneralI like Windows Powershell approach Pin
Maruf Maniruzzaman26-Aug-09 16:21
Maruf Maniruzzaman26-Aug-09 16:21 
GeneralRe: I like Windows Powershell approach Pin
Md. Marufuzzaman27-Aug-09 10:59
professionalMd. Marufuzzaman27-Aug-09 10:59 
Generaldepends on the environment Pin
FlowerX25-Aug-09 22:23
FlowerX25-Aug-09 22:23 
GeneralRe: depends on the environment Pin
Cristian Amarie28-Aug-09 7:15
Cristian Amarie28-Aug-09 7:15 
GeneralNullables Pin
Abhishek Sur25-Aug-09 21:42
professionalAbhishek Sur25-Aug-09 21:42 
GeneralRe: Nullables Pin
FocusedWolf27-Aug-09 15:15
FocusedWolf27-Aug-09 15:15 
Ya Nullable is fun to use. Especially Nullable.GetValueOrDefault(value to use if the return has no value).

But in reality i prefer empty types first if available... like String.Empty, IntPtr.Zero...
Generalsometimes empty sometimes null Pin
ecooke24-Aug-09 6:21
ecooke24-Aug-09 6:21 
GeneralA single answer for all cases? Pin
Stephen Hewitt24-Aug-09 5:20
Stephen Hewitt24-Aug-09 5:20 
GeneralRe: A single answer for all cases? Pin
Chris Maunder24-Aug-09 6:06
cofounderChris Maunder24-Aug-09 6:06 
GeneralRe: A single answer for all cases? Pin
PIEBALDconsult24-Aug-09 13:36
mvePIEBALDconsult24-Aug-09 13:36 
GeneralRe: A single answer for all cases? Pin
Myddyn28-Aug-09 2:45
Myddyn28-Aug-09 2:45 
GeneralIdeally, such function would return an option type. Pin
Nemanja Trifunovic24-Aug-09 3:56
Nemanja Trifunovic24-Aug-09 3:56 
GeneralRe: Ideally, such function would return an option type. Pin
Chris Maunder24-Aug-09 6:09
cofounderChris Maunder24-Aug-09 6:09 
GeneralRe: Ideally, such function would return an option type. Pin
Nemanja Trifunovic24-Aug-09 7:03
Nemanja Trifunovic24-Aug-09 7:03 
GeneralRe: Ideally, such function would return an option type. Pin
Jörgen Sigvardsson29-Aug-09 10:21
Jörgen Sigvardsson29-Aug-09 10:21 
GeneralYou guys are too trusting Pin
Chris Maunder24-Aug-09 1:50
cofounderChris Maunder24-Aug-09 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.