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.
So who will regret a so weird keyword?

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:
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.
 
Thank you Roger for that good idea.
eiffelzone is a treasure.
 
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



<< Home

This page is powered by Blogger. Isn't yours?