[Oberon] How to write this program in Oberon-07?

Chris Burrows cfbsoftware at gmail.com
Fri Jan 28 00:15:30 CET 2022


On Tue, Jan 25, 2022 at 4:06 AM Jörg <joerg.straube at iaeth.ch> wrote:

>
>
> There is a long debate whether an ELSE in a CASE is something good or bad.
>
> That’s a little bit comparable to LOOP/EXIT: At first sight ELSE looks
> hand. But if you really had to debug complicated code with a lot of CASE
> statements you will conclude that the ELSE is quite dangerous.
>
> Let’s assume you forgot an important CASE. Instead of being trapped
> (default behaviour of an uncovered CASE without ELSE) the ELSE catches it,
> the code goes on with perhaps totally wrong variable settings and the code
> error (forgotten CASE) is mostly unnoticed!
>

 I agree. Similar potential pitfalls can occur in IF-THEN-ELSIF ladders. It
can be a good defensive programming technique to add to the end of these:

ELSE
  ASSERT(FALSE)
END;

That will trap current (or future, if related code is changed)
possibilities that have been overlooked. As a real-life example of this I
would have saved myself several hours of head-banging this week if
problematic code I have been investigating had been implemented this way. I
was able to replace it with a (more efficient) numeric CASE statement on
this occasion.

--
Chris Burrows
CFB Software
http://www.astrobe.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20220128/4530a937/attachment.html>


More information about the Oberon mailing list