Am 09.08.2012 15:34 schrieb "David Kerr" <iandav...@gmail.com>:
> Whilst (as an OO enthusiast/bigot) I agree constantly using the enum to control behaviour (the switch statements) is bad and polymorphism is the better approach,
Don't see that. It may be the more pure approach (in OO), but not necessarily the better *in all cases*.
>a simple enum is
> so much more compact than the interface/base-class and concrete implementations
> enums are nice and descriptive.
> Java has them ;)
> I think the Java advice is to only switch on them once, to create the concrete sub-class. I also think Java held off on enums for so long because the "correct" approach is polymorphism.
>
Enums are types with a finite set of distinct named values. What's wrong with them?
Switching on enums shouldn't be more wrong than switching on int values or char values or whatever.
A behaviour is not always correct and not always doable on the original type.
> I'm just saying that, pragmatically, they have their place.
More than only 'pragmatically' I would say...
But extensibility seems wrong!
KR
Det
> --
> Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
>
>
I'm in full agreement with Dirk here. Those with a background in Java see their setup where enums are classes as more extensible and OO. Those with a C/C++/C# background see it as just adding another layer of crap over what is fundamentally simple, that an enum is just a finite set of values. This finite set is used to increase the clarity of the code written.
I'm still in the keep it simple camp, and have my fingers crossed that whenever Dart finally adds enums that they'll be the C/C++/C# style instead of the Java style.
--
I'm in full agreement with Dirk here. Those with a background in Java see their setup where enums are classes as more extensible and OO. Those with a C/C++/C# background see it as just adding another layer of crap over what is fundamentally simple, that an enum is just a finite set of values. This finite set is used to increase the clarity of the code written.I'm still in the keep it simple camp, and have my fingers crossed that whenever Dart finally adds enums that they'll be the C/C++/C# style instead of the Java style.
On 08/14/2012 02:15 PM, Florian Loitsch wrote:
On Thu, Aug 9, 2012 at 7:29 PM, Don Olmstead <don.j.o...@gmail.com <mailto:don.j.olmstead@gmail.com>> wrote:
I'm in full agreement with Dirk here. Those with a background in
Java see their setup where enums are classes as more extensible
and OO. Those with a C/C++/C# background see it as just adding
another layer of crap over what is fundamentally simple, that an
enum is just a finite set of values. This finite set is used to
increase the clarity of the code written.
I'm still in the keep it simple camp, and have my fingers crossed
that whenever Dart finally adds enums that they'll be the C/C++/C#
style instead of the Java style.
The C/C++/C# enums are generally a poor fit for dynamically typed languages. Basically they just give a different names to integers and use some static checking to provide some nice properties (like making sure that a switch is exhaustive).
In a dynamically typed language this is less useful, since the enum-type disappears at runtime. A completely untyped program would have almost no benefit from enums.
why do you think that enums should loose their type at runtime ?
enum can be implemented as value type, and boxed when necessary.
Rémi
On 08/14/2012 02:15 PM, Florian Loitsch wrote:
why do you think that enums should loose their type at runtime ?
On Thu, Aug 9, 2012 at 7:29 PM, Don Olmstead <don.j.o...@gmail.com <mailto:don.j.olmstead@gmail.com>> wrote:
I'm in full agreement with Dirk here. Those with a background in
Java see their setup where enums are classes as more extensible
and OO. Those with a C/C++/C# background see it as just adding
another layer of crap over what is fundamentally simple, that an
enum is just a finite set of values. This finite set is used to
increase the clarity of the code written.
I'm still in the keep it simple camp, and have my fingers crossed
that whenever Dart finally adds enums that they'll be the C/C++/C#
style instead of the Java style.
The C/C++/C# enums are generally a poor fit for dynamically typed languages. Basically they just give a different names to integers and use some static checking to provide some nice properties (like making sure that a switch is exhaustive).
In a dynamically typed language this is less useful, since the enum-type disappears at runtime. A completely untyped program would have almost no benefit from enums.
enum can be implemented as value type, and boxed when necessary.
Rémi