[Oberon] A CASE quiz
bob at web-options.com
Fri Feb 16 13:36:29 CET 2018
The bug arises because the programmer has tried to hand-optimise the code at the expense of clarity. Prevention is better than cure. My approach to this, regardless of whether or not CASE has an ELSE clause, would have been
CASE ch of
"A" : value := 0 |
"B" : value := 1 |
"C" : value := 2 |
"D" : value := 3 |
"E" : value := 0 |
and so on.
In this way it can be seen quite clearly if any input values are missing, and the duplication of output values is also apparent. Let the compiler do the optimising.
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Chris
> Sent: Friday, 16 February, 2018 12:30 PM
> To: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
> Subject: Re: [Oberon] A CASE quiz
> > -----Original Message-----
> > From: Jörg [mailto:joerg.straube at iaeth.ch]
> > Sent: Friday, 16 February 2018 10:37 PM
> > To: chris at cfbsoftware.com; 'ETH Oberon and related systems'
> > Subject: RE: [Oberon] A CASE quiz
> > Okay. "Q" and "T" are not mentioned and will be trapped.
> Good effort but only 5/10 I'm afraid ;-) You were right about "Q" but "T" IS
> there. You have inadvertently helped to illustrate that even skilled
> programmers make these sorts of mistakes.
> > If you know that for "Q" and "T" the value should be 0 then why not
> > mention them explicitly.
> That's the whole point of the quiz. "Q" should be 2 but the programmer
> forgot it altogether.
> The ELSE swallows it up without it being noticed (!!!), but the NoElse results
> in a runtime error so alerts the programmer that something needs fixing.
> The earlier in the software lifecycle that an error is detected, the cheaper it is
> to fix it.
> > We really have to see, how many of us did detect that the numeric CASE
> > is not implemented (yet) in ORP.Mod?
> It has been previously discussed here a couple of years ago:
> Chris Burrows
> CFB Software
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
More information about the Oberon