Re: some comments about our C++ code...


Subject: Re: some comments about our C++ code...
From: Mike Nordell (tamlin@algonet.se)
Date: Sun Apr 15 2001 - 15:05:14 CDT


Aaron Lehmann wrote:
> You're right on everything, except for:
>
> On Sun, Apr 15, 2001 at 05:16:31PM +0200, Joaqu?n Cuenca Abela wrote:
> > 3) Please, please, please: NO public/protected variables. Period. Try
> > to avoid public virtual members, too.
> > This one need a bit of collaboration from everybody. I will not go
> > through all the code and fix that. It should be fixed in an incremental
> > way with the help of everybody.
>
> This is crazy.

Is it? Then the worlds best C++ designers, developers and the inventor of
C++ himself must be insane, and you would be one of the few well educated,
experienced, and respected sane C++ developers on this planet? Get real!

I know this is just ignorance on your behalf, but when that ignorance
attacks good design principles it's sometimes easy to loose ones temper.

> Why is using foo->get_bar() better than foo->bar other
> than adding complexity and obfuscating the code?

Class implementation details can change while interfaces stay the same.
Getters/setter (accessors/mutators) are just slightly better than plain data
access, but not really good.

A class is to provide a behaviour, and its interface shall be minimal and
complete. If you need direct data access to a class, something is screwed
with the design. Either the class itself doesn't provide the necessary
behaviour, or the design is just plain wrong.

If we take a small and pretty recent example that should be easy to
understand:
Imagine you'd have direct access to the internal data of UT_String. You
could SEGV anything using it in notime by messing with its *internal* data,
but using it's interface in a reasonable way (i.e. not trying to allocate a
string 4711 GB just to make a point) it's much harder (like close to
impossible) that things screw up.

How come so many *nix users seem to passionately *hate* good design???

> Ok, maybe I'm a renegade C programmer who never learned.

Perhaps, and you're the only to decide if you want to learn...

/Mike



This archive was generated by hypermail 2b25 : Sun Apr 15 2001 - 15:04:42 CDT