Wednesday, October 18, 2006
RIP affairs: the unique case
Yesterday, i had the surprise to discover that the keyword unique has deappeared! Hmm, well, lastly it disappeared from the Eiffel language of ECMA.
There are many good reasons to remove that keyword.
Frankly, me! I will regret it a lot, because in spite of all these disavantages, I made use of it often and regularly.
And now? What to do for my programs that after 200 lines of features enumeration just say: INTEGER is unique? Well for it, I have a good solution. Because they are generated by some scripts, I would update these scripts if in one hypothetical day I have to program for ECMA eiffel.
And for my day to day programming where I need few features in the list? Okay I will use my delicate fingers on all these unpleasant keys to enter explicitly the type and the value. Does somebody have a better idea for a lazy man?
There are many good reasons to remove that keyword.
- there is no way to have coercition to the defined subset by the language except by putting in many contracts that x.in_range(my_first,my_last)
- there is no way to specify a mapping to a given numeric sequence (ex: as in C, to tell the value of the first, the remaining being set with increments of one) what can be usefull in cases
- where mapping the first element to zero has good algorithmic properties
- where a same integer can receive values of 2 or more not overlapping series, but:
- compilers are free to make sequences that overlap (for example all the sequences begin with zero), then,
- the consistancy of select have to be checked: when a unique feature appears in some expression of the when clause, all the expressions in all when clauses of the select must be features of the same uniqe list.
Frankly, me! I will regret it a lot, because in spite of all these disavantages, I made use of it often and regularly.
Rest in peace dear keyword.
We will never forget you, you was so unique!
And now? What to do for my programs that after 200 lines of features enumeration just say: INTEGER is unique? Well for it, I have a good solution. Because they are generated by some scripts, I would update these scripts if in one hypothetical day I have to program for ECMA eiffel.
And for my day to day programming where I need few features in the list? Okay I will use my delicate fingers on all these unpleasant keys to enter explicitly the type and the value. Does somebody have a better idea for a lazy man?
Comments:
<< Home
Some uses of the "unique" keyword can be replaced (and indeed enhanced) using a utility in Andreas Leitner's "ETOOLS" package:
http://eiffelzone.com/esd/etools/index.html
Andreas's "Eiffel Constant Generator" (ecg) takes an enumeration (such as a series of colour codes) and produces a class that handles those codes internally as INTEGER values.
The class generated by ecg includes introspection, output formatting, range checking etc. The package seems to be from 2001, and may require a tweak or two to use with modern compilers.
http://eiffelzone.com/esd/etools/index.html
Andreas's "Eiffel Constant Generator" (ecg) takes an enumeration (such as a series of colour codes) and produces a class that handles those codes internally as INTEGER values.
The class generated by ecg includes introspection, output formatting, range checking etc. The package seems to be from 2001, and may require a tweak or two to use with modern compilers.
My own notion of an even better solution would be to support enumerations as full-bodied objects. I've worked in a couple of environments that do, and I think it's a shame that Eiffelists have to resort to code generation tools or roll-your-own code for something that should be so basic.
That is a good idea too.
Maybe a prefix to the class?
For exemple:
enumeration class X feature
a, b, c, d
end
With particular rules, of course:
- inherit automatically from ENUMERATION that defines first, last, next, previous, to_integer, as_integer, is_valid_integer
- features have no body (but can have comment)
- is automatically frozen
Post a Comment
Maybe a prefix to the class?
For exemple:
enumeration class X feature
a, b, c, d
end
With particular rules, of course:
- inherit automatically from ENUMERATION that defines first, last, next, previous, to_integer, as_integer, is_valid_integer
- features have no body (but can have comment)
- is automatically frozen
<< Home