Re:Avoid Null Checks by Replacing Finders with Tellers
by jlarocco on Monday June 17, 2013 @02:21PM
(#5894911)
I didn't mean to imply it's a good idea or not. In my own code I'd use the null check and throw an exception. It's suspicious that it's trying to update a non-existent record, so I'd usually want it to break so I can fix the underlying logic bug.
I was simply pointing out that the technique is available in other languages without using lambda and/or blocks.
Re:Avoid Null Checks by Replacing Finders with Tellers
by dragonwriter on Monday June 17, 2013 @04:07PM
(#5895590)
> Since it's a nasty dirty hack that tends to misbehave on bad data instead of failing cleanly
This assumes that an empty result set of a finder is "bad data"; there are times when this is true (in which case, the basic "teller" idiom as illustrated here isn't a good choice), but there are lots of times where it isn't, too.
Re:Avoid Null Checks by Replacing Finders with Tellers
by tbrownaw on Monday June 17, 2013 @04:17PM
(#5895662)
There's also the case where I forget a unique index or get the query wrong, and get several records when I'm only expecting one.
Re:Avoid Null Checks by Replacing Finders with Tellers
by dragonwriter on Monday June 17, 2013 @04:22PM
(#5895692)
The teller strategy can work for those; that's all checking that can be done in the teller (or, in the case of teller-implemented-on-top-of-finder) in the finder. There's no reason to repeat the logic checking for this case all over the application.
Since it's a nasty dirty hack that tends to misbehave on bad data instead of failing cleanly, I generally restrict it to experimental/throwaway code. Seeing it recommended as a good idea is a bit WTF.