Ondrej Hrabal
2004-10-25 17:48:06 UTC
Hi all!
I'd like to know what's your opinion on the enumeration types missing
in Oberon. I think it was a big mistake to remove them. I can't see a
satisfactory way to replace them:
1) Integer constants
-it's extremely easy to make an error in the declaration (e.g. use the
same value twice)
-if you need to add a new constant and still preserve a logical
ordering of the declarations you may have to increment all the values
-these declarations are the ugliest part of any Oberon source
-the programmer is forced to work with low-level information that he
doesn't want to care about and even make this information a part of
public interfaces
-the interfaces doesn't make it clear which INTEGER parameters and
which constants are to be used together
-it's possible to compute the result of "(Monday + LeftAlign) MOD
SunkenBorder" and pass it to a SetColor procedure
-and so on
Conclusion: good enough for a C programmer
2) Object types
For every enumeration type we could write a separate module that would
contain the following:
-an abstract type representing the enumeration (e.g. ButtonStyle,
DayOfWeek)
-a set of private subtypes implementing the individual values
-a set of factory procedures for the individual values (using the
Flyweight pattern for efficiency)
-a public (LIMITED) "mutable wrapper" type together with a factory
procedure
From a client's point of view this would be perfect, but definition of
an average enumeration type might take some 200 or 300 lines of
code...
3) My solution: a stupid one, but IMHO still the best one
Consider I need an alignment parameter with possible values Left, Top,
Right, Bottom and Center. I will happily declare it as a CHAR and use
self-explanatory character literals 'L', 'T', 'R', 'B', 'C'. This
remedies many of the "INTEGER solution" problems, but of course not
all.
Niklaus Wirth explained that the problem with the enumeration types
was that they weren't extensible, so they had to be removed from the
object-oriented Oberon. I think this was a mistake. After all, who
would like to extend the BOOLEAN type with a new value (perhaps
MAYBE)? Indeed, extension of an enumeration type would break all
existing implementations as they just wouldn't know what to do with
the new values.
=> The fact they are not extensible is an important feature, not a
weakness!
What's your opinion on the subject? And do you know any other solution
to simulate enum types?
Andy
I'd like to know what's your opinion on the enumeration types missing
in Oberon. I think it was a big mistake to remove them. I can't see a
satisfactory way to replace them:
1) Integer constants
-it's extremely easy to make an error in the declaration (e.g. use the
same value twice)
-if you need to add a new constant and still preserve a logical
ordering of the declarations you may have to increment all the values
-these declarations are the ugliest part of any Oberon source
-the programmer is forced to work with low-level information that he
doesn't want to care about and even make this information a part of
public interfaces
-the interfaces doesn't make it clear which INTEGER parameters and
which constants are to be used together
-it's possible to compute the result of "(Monday + LeftAlign) MOD
SunkenBorder" and pass it to a SetColor procedure
-and so on
Conclusion: good enough for a C programmer
2) Object types
For every enumeration type we could write a separate module that would
contain the following:
-an abstract type representing the enumeration (e.g. ButtonStyle,
DayOfWeek)
-a set of private subtypes implementing the individual values
-a set of factory procedures for the individual values (using the
Flyweight pattern for efficiency)
-a public (LIMITED) "mutable wrapper" type together with a factory
procedure
From a client's point of view this would be perfect, but definition of
an average enumeration type might take some 200 or 300 lines of
code...
3) My solution: a stupid one, but IMHO still the best one
Consider I need an alignment parameter with possible values Left, Top,
Right, Bottom and Center. I will happily declare it as a CHAR and use
self-explanatory character literals 'L', 'T', 'R', 'B', 'C'. This
remedies many of the "INTEGER solution" problems, but of course not
all.
Niklaus Wirth explained that the problem with the enumeration types
was that they weren't extensible, so they had to be removed from the
object-oriented Oberon. I think this was a mistake. After all, who
would like to extend the BOOLEAN type with a new value (perhaps
MAYBE)? Indeed, extension of an enumeration type would break all
existing implementations as they just wouldn't know what to do with
the new values.
=> The fact they are not extensible is an important feature, not a
weakness!
What's your opinion on the subject? And do you know any other solution
to simulate enum types?
Andy