Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!umich!vela!schemers From: schemers@vela.acs.oakland.edu (Roland Schemers III) Newsgroups: comp.lang.c++ Subject: Re: namespace (rethought & reiterated) Message-ID: <5318@vela.acs.oakland.edu> Date: 3 Mar 91 17:38:26 GMT References: <2620020@otter.hpl.hp.com> <4196@lupine.NCD.COM> Reply-To: schemers@vela.acs.oakland.edu (Roland Schemers III) Organization: Oakland University, Rochester MI Lines: 60 In article <4196@lupine.NCD.COM> rfg@NCD.COM (Ron Guilmette) writes: > >Namespace pollution is indeed an important and, I believe, an unsolved >problem in C++. > >The idea proposed here is to use include files as individual namespace >"modules". That's not a bad idea, however C++ already has something >which can serve pretty well as a namespace "module". It's called a >class. Consider a header file like: I just had namespace pollution spoil my weekend. We just got in Motif from DEC, and it has C++ compatible headers, so I was all set to start hacking away... Till I noticed they had a 'typedef char *String;' which was used extensivly through all the headers. Now I can't use my handy dandy String class that is part of my library. So I basically had to redesign my library. I had to choices: 1. Make a class that contained all my classes, and access my String class like RJS::String 2. Prefix all my objects with RJS_ I picked number 2. Now all my objects begin with RJS_ (Roland J Schemers :-)). This does lead to very verbose objects: RJS_PrinterQueueIterator For example, but it does protect me for the most part. Until someone starts using their own RJS_ prefix!!! To get over verbose names I think I am going to make an include file called (all my includes are in their own directory), which contains: #ifndef RJS_TYPE_H #define RJS_TYPE_H class RJS_String; typedef RJS_String String; #endif ... more classes... #endif This file could be modified to avoid namespace problems. Of course one this happens all the code that used the typedef version must be changed! So for now I am just using the verbose RJS_ names of all my objects. Either way this is something that needs to be dealt with. Roland -- Roland J. Schemers III Systems/Network Manager schemers@vela.acs.oakland.edu (Ultrix) Oakland University schemers@argo.acs.oakland.edu (VMS) Rochester, MI 48309-4401 You can tune a piano, but you can't tuna VMS! (313)-370-4323