News for hackers. Stuff that matters.
Re:Avoid Null Checks by Replacing Finders with Tellers by masklinn on Monday June 17, 2013 @01:49PM (#5894665)
The issue here is that the semantics are weird, an iteration block is expected to iterate 0..n times, not 0..1. I know I'd never expect a loop primitive to be used as a conditional.

And the context manager can't handle this case, as it's not able to skip the block body.

Re:Avoid Null Checks by Replacing Finders with Tellers by tbrownaw on Monday June 17, 2013 @02:15PM (#5894858)
I do this in my PL/SQL code occasionally, when I'm feeling lazy and either don't want to handle errors properly or want to take advantage of auto-defined iteration variables.

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.

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.