top | item 7953161

(no title)

jlujan | 11 years ago

presumably, as a programmer, you check return values. Especially if they could be a null reference

discuss

order

mike_hearn|11 years ago

Any reference in Java can be null, as is the case in most languages. So developers only check the ones they know "could" be null, in normal operation. If you only distribute your app via the Play Store, attempting to access it will never fail, thus there's no more point in checking for null pointers than there is in checking the result of String.split: it will never fail, short of something wacky and unexpected like a broken JVM.

jacquesm|11 years ago

> So developers only check the ones they know "could" be null, in normal operation.

Not the good ones. Normal operation isn't when you're dealing with a mobile device, there could be any number of reasons why your app can't reach a certain service delivered by some API so better to be prepared for that eventuality.

edgyswingset|11 years ago

Actually the way you check for Google Play services doesn't involve nulls at all, it's a status code.

And related to null-checking, I took the pervasive approach in one of my apps for fun. It's hilarious - almost 1/3 of my app is checking if something is null. Makes you wish for a switch to a language where nulls don't exist unless explicitly asked for.

njs12345|11 years ago

Not always. If you use maps, for instance, then calling getMap on a map fragment when Play Services isn't installed will give you back a null reference.