Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

null object swallows calls - good idea?

Name: Anonymous 2011-12-26 5:10

often you have to explicitly test whether something is null before you try to use properties or methods of it, otherwise you will get some kind of error (java: NullPointerException, javascript: ReferenceError)

in other languages the call is just ignored (objective c, i think)

in others (coffeescript, groovy), there is a "safe access operator" that lets you get at properties of an object, and will just return null if it does not exist.

the problem with the first way is that your code becomes littered with null tests and every function becomes longer.

the problem with the second way is that what you may consider an error just becomes a silent action of setting something to null.

is one of these styles better? i am thinking null swallowing calls and not causing an error is better, because it is more terse and more often does what you want

Name: Anonymous 2011-12-26 8:39

My girlfriend won't swallow.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List