Topic: Adding more classes (was: SizeOf Operator Overloadable?)
Author: lars@distinct.se (Lars Pensjo)
Date: Tue, 18 Oct 1994 14:36:49 GMT Raw View
In article <rfgCxuvHn.CrJ@netcom.com> rfg@netcom.com (Ronald F. Guilmette) writes:
...
>I'd prefer to be able to solve this problem _without_ having to invent
>new (and gratuitous) types.
>
>(I could say the same thing about a _lot_ of problems in C++. Sadly, it
>seems that the ``C++ solution'' to an awful lot of relatively simple
>problems is to have the programmer create a new type. :-(
Now, this is interesting. I have the same feeling, and I don't create new
classes unless I really have to. But maybe this is the wrong view when
using C++ ? Your use of the word "gratuitous" is interestingly ambigous here.
My dictionary tells me it means either "free" (sort of) or "without enough
reason".
I have especially felt this way when creating GUI applications. Hesitating
to make a new kind of button, to be derived from the standard button, etc. I
usually prefer to have a button which is configurable by setting attributes.
There are at least three reasons I hesitate to create new classes:
* It is a "lot of" initial work. You need an extra file, adding "#ifdef",
worrying about copy-constructors, asignment operators etc.
* I worry about performance. The program grows bigger, possibly slower.
* More classes and more files makes the program harder to maintain.
The first item can be somewhat overcome by some kind of tool. Several exists.
When I think about it, I realize I can easily make some kind of macro to
emacs.
The second is probably just wrong. I can always use inline if it really
matters. Anyway, I should not worry about performance at this stage.
The last item is maybe the most important ? However, with namespaces, it is
easier to structure the source code. I also find it difficult to decide
when to remove a class.
So why not look at the other side of the coin. C++ is very flexible, because
you can so easily make your own class...
------
Lars Pensjo