Theocacao
Leopard
Design Element
Comment on "Attribute Values in Rails"
by Scott Stevenson — Oct 31
Mr eel says: you might be a bit surprised if no errors get generated and yet the input doesn't have a value in it

I think we're talking about different things. I agree setting a nil value on an attribute should raise a validation error. In Objective-C, though, you can send messages to nil without generating errors. In Ruby terms, that means you could do nil.strip!, and nil would just ignore it.

This is really helpful during development because you don't have to constantly check the nil-ness of every single object and you can stub out methods that don't actually have working objects in them.

Steve says: We're supposed to not send messages to nil anymore though. Apparently Apple can optimize msgSend if there are "NO_NIL_RECEIVERS" or whatever.

Hmmm, I vaguely remember this, but I'll have to look at it again. I'm not sure it's worth the loss in productivity and safety.

And on Intel, messages to nil are going to give different results.

True, though I think this is a secondary issue. My main interest is making sure the app doesn't just blow up when you talk to nil.
Back to "Attribute Values in Rails"
Design Element

Copyright © Scott Stevenson 2004-2015