[Oberon] Why no enumeration types?
private at claudio.ch
Wed Jul 28 00:36:35 CEST 2021
> TYPE Colors = (red, green, blue);
> Later in this module you change the enumeration to:
> TYPE Colors = (red, green, yellow, blue);
> If you don't recompile all modules that import this module, what happens with this code?
> FOR i := MIN(Colors) TO MAX(Colors) DO ... END;
> VAR table: ARRAY Colors OF BOOLEAN;
> Your program will have unexpected behaviours or will simply crash. To solve this, you have to recompile all the clients.
Similar problems if you declare three INTEGER red=0, green=1, blue=2 and
then change them to yellow=2, blue=3
If you have VAR table: ARRAY 3 OF BOOLEAN; when you add an additional
color it can reslt in table[i] to be outside of the array boundaries
resulting in a crash.
Even worse, FOR i:=0 TO 2 DO ... END; will miss something once you
introduce additional colors and your application will misbehave in
From my experience, finding errors that occur at runtime are so much
costlier than having the compiler report an error or even forcing a
recompilation of modules.
More information about the Oberon