comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Case statement and Integers.
Date: Sat, 20 Apr 2002 18:31:04 GMT
Date: 2002-04-20T18:31:04+00:00	[thread overview]
Message-ID: <Itiw8.3026$dk4.1626810405@newssvr14.news.prodigy.com> (raw)
In-Reply-To: vChw8.79741$G72.57096@sccrnsc01

>       case numbers(j) is
>               when numbers(j) < pivot => swap(left_swap, right_swap);
>               when numbers(j) > pivot => swap(right_swap, left_swap);
>               when numbers(j) = pivot => null;
>               when others => null;

  The items after the "when" must be constant values of "numbers(j)".
This code has dynamic boolean expressions.  "case" is not just another
syntax for "if then".  When the compiler sees a "case" statement it
should, at least conceptually if not in implementation, be able to create
a jump table indexed by the value of "numbers(j)".  It clearly can't do
that here.
If you had a comparison function
  type Compare_Results is (LT, EQ, GT);
  function Compare(Left, Right : Numbers_Type) return Compare_Results;
then you could say
  case Compare(numbers(j), pivot) is
    when LT =>
    when GT =>
    when EQ =>
  end case;
because the compiler could create a three-entry jump table.

> Using an if..else statement wouldn't be original.
  Bicycling to Hawaii is original - but it won't work either.  In
Software Engineering, the point is to make something that works, not
necessarily something original.  In fact, since you will abandon most of
your code to your maintenance successors (one hopes you move on to new
things!), and originality will just confuse them, originality itself is a
downright *negative* aspect of code, to be used only when the negative is
outweighed by the positive benefits of the novel technique.



  reply	other threads:[~2002-04-20 18:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-20 16:42 Case statement and Integers Wannabe h4x0r
2002-04-20 17:04 ` Rhoady
2002-04-20 17:11 ` Alan Reynolds
2002-04-20 17:32   ` Wannabe h4x0r
2002-04-20 18:31     ` tmoran [this message]
2002-04-21  3:59       ` Wannabe h4x0r
2002-04-22  3:01       ` Robert Dewar
2002-04-22  5:14       ` Anders Wirzenius
2002-04-20 21:26     ` Ted Dennison
2002-04-20 19:14 ` Vadim Godunko
2002-04-22  3:05   ` Robert Dewar
2002-04-22  8:41     ` Vadim Godunko
2002-04-22 13:16       ` Robert Dewar
2002-04-23  6:38     ` Wannabe h4x0r
2002-04-22 16:58 ` Anatoly Chernyshev
2002-04-22 17:55   ` tmoran
2002-04-22 19:51     ` Anatoly Chernyshev
2002-04-24 11:41   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
2002-04-22  9:11 Grein, Christoph
replies disabled

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