Re: Why Generics?




"Thomas G. Marshall" <tgm2tothe10thpower@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message news:aMVee.3094$w56.2630@xxxxxxxxxxx

> If that's what you were worried about then enums were not "truly needed"
at
> all.

I agree with you, but only in the "possible" sense of "needed", not in the
"desirable" sense. In that sense of the word, your claim is already proven
by the fact that the new enumerations are (in my understanding) just a
little syntactic sugar provided by the javac compiler. So clearly type
safe enums were always possible.

However, you could say the same thing about the new enhanced "for"
statement. Yes, it's possible for me to to write a loop that is
effectively coding "for each element of this list", but (IMO) it is
substantially better to be able to CODE it as "for each element" rather than
"something that translates to for each element".

For example... which is more readable:

int sum = 0;
for (int i=0, i<a.length() ; i++) {sum += a[i]} ;
print(sum/a.length());

or:
print(average(a));

The problem with the example you gave (IMHO) is in what I call the
"exposition". The advantage of enumerations (and for each and a bunch of
the othernew features) is that they provide a syntax to DIRECTLY express a
basic operation, and thus expose the operation more directly.


.



Relevant Pages

  • Re: Type alias in C#
    ... Except that all FCL enumerations list ... the keyword "Structure" not apply to the presence of the keyword ... I see enums as restricted structures, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Whats the best language to learn...
    ... over the arrays of vertices, ... loop over the selected models; ... recently my edge construction and shadow-volume rendering code ... but enums just make it easier and quicker to make ...
    (comp.programming)
  • Re: Enumeration idioms: Values from different enumerations
    ... > look at the reasons behind wanting enumerations in the first place, ... In my opinion, rather than make all enums fail equality testing, two ...
    (comp.lang.python)
  • Re: Enumerations
    ... > First I'm going to talk about enums. ... you have some serious misconceptions about enumerations. ... compiler error - illegal implicit conversion to int. ...
    (comp.lang.cpp)
  • Re: Enumeration idioms: Values from different enumerations
    ... >> Enums are not conceptually subclasses of integers. ... >> be a useful method to implement enumerations. ... They are discrete values, they can be ordered in many different ways ... and compared for equality (fish is not bird). ...
    (comp.lang.python)