comp.lang.ada
 help / color / mirror / Atom feed
* Thought this was funny
@ 2003-10-21 19:49 Xenos
  2003-10-21 20:26 ` Ching Bon Lam
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Xenos @ 2003-10-21 19:49 UTC (permalink / raw)


Reviewing some old code we are converting from Ada 83 to 95, I came across
this:

case <boolean expression> is
  when true =>
       <do something>

  when false =>
       <do something else>

end case;


Kind of made me chuckle a little.  The guy how wrote it is Canadian, so I
took to calling it the "Canadian If Statement" (not in a cruel way).


DrX





^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: Thought this was funny
@ 2003-10-22  6:44 christoph.grein
  2003-10-22  7:31 ` Dmitry A. Kazakov
  2003-10-23  2:17 ` Wes Groleau
  0 siblings, 2 replies; 23+ messages in thread
From: christoph.grein @ 2003-10-22  6:44 UTC (permalink / raw)
  To: comp.lang.ada

> case <boolean expression> is
>   when true =>
>        <do something>
>
>   when false =>
>        <do something else>
>
> end case;

What's so funny about this code. I also normally use if-statements with booleans but 
there are circumstances where a case statement seems more appropriate to the 
problem at hand.

Take e.g. kind of double-buffering. I use an array indexed by Boolean and switch 
via
  "X := not X;"

In such cases, neither True nor False denote something which is wrong or right, 
so I prefer the case statement.

Switching with a two-valued enumeration is not so elegant, you need a switch 
table or a case statement instead of the simple "X := not X;".

[Ducking away because this is an abstraction inversion :-]



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2003-10-23  2:17 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-21 19:49 Thought this was funny Xenos
2003-10-21 20:26 ` Ching Bon Lam
2003-10-21 20:44   ` Lutz Donnerhacke
2003-10-21 20:36 ` Ed Falis
2003-10-21 21:08 ` Stephane Richard
2003-10-21 22:16   ` Robert I. Eachus
2003-10-21 22:24     ` Ed Falis
2003-10-22  0:36       ` Robert I. Eachus
2003-10-22  1:37         ` Ed Falis
2003-10-22  3:56           ` Robert I. Eachus
2003-10-22 13:44             ` Ed Falis
2003-10-21 23:13     ` Georg Bauhaus
2003-10-22  0:23     ` Alexandre E. Kopilovitch
2003-10-21 22:23   ` Simon Wright
2003-10-22  2:57 ` Steve
2003-10-22  6:26 ` Anders Wirzenius
2003-10-22  6:36 ` Vinzent 'Gadget' Hoefler
2003-10-22 12:38   ` Christopher J. Henrich
2003-10-22 15:00 ` Martin Dowie
  -- strict thread matches above, loose matches on Subject: below --
2003-10-22  6:44 christoph.grein
2003-10-22  7:31 ` Dmitry A. Kazakov
2003-10-22  8:48   ` Vinzent 'Gadget' Hoefler
2003-10-23  2:17 ` Wes Groleau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox