Re: [Alephmodular-devel] Enum versus class?
Status: Pre-Alpha
Brought to you by:
brefin
From: Dietrich E. <die...@zd...> - 2003-03-02 06:51:44
|
On Saturday, Mar 1, 2003, at 11:27 US/Pacific, Br'fin wrote: > From: "Br'fin" <br...@ma...> > Date: Sat Mar 1, 2003 11:27:59 US/Pacific > To: ale...@li... > Subject: [Alephmodular-devel] Enum versus class? > > As part of dealing with abstracting the display stuff I found myself=20= > wanting to back off a little and implement a BitDepth enum. Or=20 > similar. So I've been dabbling with it, and in wanting some class=20 > related foo I ended up developing the following: [...] > And I'm trying to figure out if this is appropriate or overblown. If=20= > it's overblown then I should just fall back to using the enum by its=20= > lonesome. <rant> Hate to break it to you, but that is most abuse I have ever seen the=20 C++ language take. In Ada we would write: type Bit_Depth is (Depth_8, Depth_16, Depth_32); or something along those lines. In C, it would be: typedef enum _bit_depth { depth_8, depth_16, depth_32 } bit_depth; If C++ is such a superior language, why does it take so damn much code?=20= The above two examples provide the same functionality (although only=20= the Ada version has the bounds checking). THE SAME FUNCTIONALITY. I=20 could use less code programming it in assembly. Why the hell do you=20 need bounds checking anyway? private vs. public? A class? Damn, I=20 would have just used existing functionality. It is no wonder that the=20= Marathon engine doesn't see any significant changes when people waste=20 so much effort on things that really only need one line of code. I'm not really bashing C++, it's just that it has it's strong points=20 and its weak points like most languages (Intercal a notable exception).=20= C++ has exceptions - these are good! Use them! That way you don't=20 have to manually check for errors -- essentially, instead of doing an=20 operation and asking "Was there an error?", if there is an error it=20 takes care of itself. Classes and namespaces: another good thing. =20 Instead of calling BKSparseArray_GetValues (...) we can just do=20 something like myArray.GetValues (...), or even myArray[...]. Making=20 classes for everything you can think of? Well, do that in Ada because=20= Ada was designed to do that, and you can imitate it with C using enum=20 and struct, but class is a beast of a different nature and it should be=20= treated that way. C++ has a dichotomy of classes and not-classes, you=20= have to deal with this or use a different language like Smalltalk or=20 Python. I bring this up because I hate to see projects make the mistakes that=20 are so damn ubiquitous these days... some things should be learnt=20 though experience, but large projects are not places for such learning=20= of design methods. ----- "The main problem for the C++ community today is to use Standard C++ in=20= the way it was intended rather than as a glorified C or a poor man's=20 Smalltalk." =97 Bjarne Stroustrup (inventor of C++), "Getting =46rom The = Past=20 To The Future" , p. 23 C++ Report, SIGS Nov/Dec 1999 Vol1 No.10 C++: The power of assembly language with the ease of use of assembly=20 language. "I invented the term Object-Oriented, and I can tell you I did not have=20= C++ in mind." =97 Alan Kay "C++ : an octopus made by nailing extra legs onto a dog" </rant>= |