> On Nov 21, 2016, at 09:37, David Storrs <david.sto...@gmail.com> wrote:
> 
> In Perl I would often write:
> 
> sub do_something {
>     return unless ( some necessary condition is met );
>     ... do the thing ...
> }
> 
> In Racket I could wrap the rest of the procedure in an (if), but that adds an 
> unnecessary level of indentation and feels clunky.  Is there a clean solution?

Playing the role of irritating ideologue, it’s … me!

Yes, there’s let/ec, but my (limited) experience in industry suggests that 
reading functions that use ‘return’ liberally can be massively more difficult 
than one that uses ‘if’ or a related form. I would argue that the call/ec 
doesn’t actually make the code less clunky, it just hides the clunkiness, and 
makes the code harder to read, to boot. In the absence of return, you can 
generally easily deduce when control flow reaches a particular point (“we only 
get here if x is > 0 and the string is empty”). In the presence of return, this 
becomes “we only get here if x is > 0 and the string is empty and one of these 
19 incomprehensible clauses didn’t trigger a return.” 

I do think that call/ec makes sense in some circumstances; for instance, if you 
want to bail out of a deeply nested call, and the intervening calls are to 
functions that someone else wrote. But generally, I try to bite the bullet and 
use the if (or cond), on the theory that when I come to read my own code next 
year I’ll have some idea what it’s doing.

BTW: yes, my soapbox is huge. Huge!

John



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to