Other's experiences with C++

Matthew Tuck matty@box.net.au
Tue, 15 Dec 1998 22:58:58 +1030


Hans-Dieter.Dreier@materna.de wrote:

> I found reading in the newsgroup comp.lang.c++.moderated quite interesting.
> It shows many facets of language design (traps to fall into as well as nice 
> ideas) that can only be gotten from extensive use of a language by many
> different persons with very different opinions and programming styles. C++
> is especially good suited for this as it satisfies all of the above
> conditions and is quite complex (IMHO rather too complex).

Hmm, what is C++ suited to?  Did you mean very different programming
styles?  I think that's why it is so big.

> Example: The notion of a "const leak" (what a term! It means that the
> compiler complains about violation of constness somewhere and the
> programmer can't find the reason), or the statement that const is hard to
> fit into a large project afterwards.

I took a look but couldn't find that thread, I'm not sure how what you
describe would occur, did anyone know?  Sounds like a compiler problem. 
Anyway, this is probably not what you're talking about, but there's
actually a hole in C++ that lets you alter constant data.

> As I'm viewing "const" primarily as some form of pre-/postcondition (BTW,
> is there a shorthand term for this? I'll call it PPC here), the above
> statements should apply to general PPCs as well. A suggestion that can be
> derived from the discussion mentioned could be to include *two* sets of
> PPCs: One generated by the user, stating the user's intentions, and one
> generated by the compiler, reflecting the current state. The compiler would
> compare these and see whether a user PPC is violated. A user could use copy 
> & paste as a rather painless way to add PPCs. It would also help finding
> PPC related problems and enhance automated documentation.

I'm not sure what you mean by PPC here.  Const is generally checked at
compile-time, while assertions are, at least logically, checked at
run-time.  If you're just referring to the const-sort-of-thing, then
they go by lots of names, and there are lots of different possibilities
in this area.

There are lots of things like const, for example, private, read-only
parameters, write-only parameters, unoverridable methods, abstract
classes.  They're all similar in that they restrict things.

If you want to go the const-sort-of-thing route, you have to work out a
way to make it unobtrusive, but I believe that can be done.  What has
been done is a sort of minimalistic thing, e.g. const.  One of the
advantages of this is documentation, it also has advantages in
extensible code systems (see my "Interprocedural Optimisation" page in
the optimisation catalogue).

Could you elaborate on this?

> Another discussion thread was about the use of name spaces: When to use,
> which names to choose, how deep to nest and so on.

> A lesson to be learned from this was that deeply nested namespaces with
> lengthy names may render error messages unreadable (as well as programs,
> BTW). As a consequence, language designers should think about ways how the
> qualification mechanism (:: . -> in C++) can be streamlined without
> sacrificing ease of use, security and clearness (use of aliases;
> transparent names which do not need qualification; ...).

There are various ways to handle this.  Stepping into namespaces is
something Pascal and Ada support.  So you can specify that you want to
step into "x.y.z.a", and then just name everything in there as a simple
variable.  There are problems, but I think they can be solved,
especially with intelligent editors.  They are similar to aliases,
except they don't really cause an aliasing problem (not realising two
names are aliases and stuffing up the algorithm).

By transparent names, do you mean the namespaces support information
hiding without requiring qualification?  I hadn't kept up with C++
namespaces, so didn't know that this sort of thing was in C++ (or maybe
it isn't).  I've thought about this before, and thought it would be a
good feature to have.

-- 
     Matthew Tuck - Software Developer & All-Round Nice Guy
                              ***
       Check out the Ultra programming language project!
              http://www.box.net.au/~matty/ultra/