[plt-scheme] required else for if ?

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Tue Sep 8 13:52:27 EDT 2009

On Tue, Sep 8, 2009 at 6:06 PM, John Clements<clements at brinckerhoff.org> wrote:
>
> On Sep 6, 2009, at 3:43 PM, Matthias Felleisen wrote:
>
>>
>> In 1991 I asked Bob Hieb (Kent's Chez Scheme buddy then, and my
>> co-researcher on theoretical stuff) what the most frequent annoying bug was
>> in the code. He ranked an accidentally omitted else branch among the top
>> three. Indeed, he said that because of this, they had agreed to use WHEN and
>> UNLESS exclusively for cases when they needed a one-armed IF and that they
>> considered all one-armed uses as a bug or a legacy issue (which they
>> corrected as soon as they touched a file).
>>
>> We have chosen to codify their restriction. It's a minor inconvenience
>> that buys a good deal of clarity.
>
> A much more evil manifestation of this occurs when you have a one-armed if,
> e.g. :
>
> (if button-is-pressed?
>  (launch-missiles))
>
> ... and it's not working, so you stick a printf in there:
>
> (if button-is-pressed?
>  (printf "x = ~v\n" x)
>  (launch-missiles))
>
> And suddenly the missiles launch without the button being pressed.
>
> Stupid, yes, but I've spent at least one late night tracking down this bug.
>

Perfect example... this should be enough to convince anyone the
benefits of the if constraint. :)
Besides I am really enjoying having the difference between if and
when. The names fit their semantics and makes code clearer.

Cheers,

Paulo Matos

> John
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>



-- 
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net


Posted on the users mailing list.