Topic: Namespaces, naming conflicts


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: 1995/06/22
Raw View
clamage@Eng.Sun.COM (Steve Clamage) writes:

>Roman.Stawski@gsi.fr (Roman.Stawski) writes:
>
>>Why not use the nested namespace mechanism to resolve conflicting
>>namespaces?
>
>> namespace MS {
>>  #include <msodbc.h>
>> }
[...]
>That won't work. By putting the MS header, for example, in your own
>namespace "MS", you declare the function MS::ODBC::Connect(). But
>Microsoft didn't define the function in that namespace, so its
>name is just ODBC::Connect(). The program won't link, since the
>declared name is different from the defined name.

It would be possible (and very useful) to create a linkage tool that
could rename all of the symbols in a library to insert a namespace
prefix.  If such tools were available, the technique that Roman Stawski
suggested could be used.

--
Fergus Henderson
fjh@cs.mu.oz.au
http://www.cs.mu.oz.au/~fjh





Author: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
Date: 1995/06/23
Raw View
Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
: It would be possible (and very useful) to create a linkage tool that
: could rename all of the symbols in a library to insert a namespace
: prefix.

Trying to introduce a common C++ name mangling scheme by the back door, eh ?





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/17
Raw View
Roman.Stawski@gsi.fr (Roman.Stawski) writes:

>Why not use the nested namespace mechanism to resolve conflicting
>namespaces?

> namespace MS {
>  #include <msodbc.h>
> }

> namespace WATCOM {
>  #include <watodbc.h>
> }

> ...
> MS::ODBC::Connect() ;
> // or
> WATCOM::ODBC::Connect() ;

That won't work. By putting the MS header, for example, in your own
namespace "MS", you declare the function MS::ODBC::Connect(). But
Microsoft didn't define the function in that namespace, so its
name is just ODBC::Connect(). The program won't link, since the
declared name is different from the defined name. They must be
considered to be different functions.

If you have all the source code, you can enclose everything in
a namespace, and recompile everything. Then put the headers in the
same namespace and everything matches.

--
Steve Clamage, stephen.clamage@eng.sun.com





Author: Roman.Stawski@gsi.fr (Roman.Stawski)
Date: 1995/06/15
Raw View
In article <DA379D.Jr6@online.tmx.com.au>, tony@online.tmx.com.au says...
>
>Rune Huseby (Rune.huseby@gpi.telemax.no) wrote:
>
>> I know that namespaces was introduced to avoid naming-conflicts across
>> libraries, but who defines the namespace names? It is possible that two
>> vendors simultanously defines equal namespaces for their libraries, like
>> 'ODBCLib' or similar. I would expect that the vendors would try to keep
>> the namespace names as short as possible, so programmers don't have to
>> write something similar to 'Microsofts_ODBC_library::Connect()'
>
>It's possible for a vendor to define a long name such as
>        Microsofts_ODBC_library
>and then define a short alias.

Why not use the nested namespace mechanism to resolve conflicting
namespaces?

 namespace MS {
  #include <msodbc.h>
 }

 namespace WATCOM {
  #include <watodbc.h>
 }

 ...
 MS::ODBC::Connect() ;
 // or
 WATCOM::ODBC::Connect() ;


--
Roman Stawski






Author: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
Date: 1995/06/16
Raw View
Roman.Stawski (Roman.Stawski@gsi.fr) wrote:
: Why not use the nested namespace mechanism to resolve conflicting
: namespaces?
:
:  namespace MS {
:   #include <msodbc.h>
:  }
:
:  namespace WATCOM {
:   #include <watodbc.h>
:  }
:
:  ...
:  MS::ODBC::Connect() ;
:  // or
:  WATCOM::ODBC::Connect() ;

Because your code will compile to calls to functions named MS::ODBC::xxxx,
whereas the libraries provided by the vendor will contain functions named
ODBC::xxxx.  Your program will then not link.

The whole point of namespaces is to get around name conflicts between
libraries, and if vendors choose to take similar function libraries and
give them exactly the same namespace name as those from other vendors then
we are right back at square one again, only with longer names this time.





Author: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
Date: 1995/06/16
Raw View
Roman.Stawski (Roman.Stawski@gsi.fr) wrote:
:  namespace MS {
:   #include <msodbc.h>
:  }
:
:  namespace WATCOM {
:   #include <watodbc.h>
:  }
:
:  ...
:  MS::ODBC::Connect() ;
:  // or
:  WATCOM::ODBC::Connect() ;

Thinking about it, life should be pretty easy for the software vendors.
They don't need to worry overmuch about choosing unique namespace names for
their libraries, since they already have one thing that uniquely identifies
them : their company name.  It's a trademark, after all.

The ordered pair <company, function> should produce unique keys as long as
all vendors ensure that they never publish two "library entites" with the
same name (unless it is in successive releases of the same library, of
course).

This last should not be too difficult to achieve, since it is the nature of
the beast that (say) Watcom is only going to publish one ODBC connectivity
library, and thus only have (say) one ODBCInitialise() function.  Every
company should be able to exert absolute control over the public entities
in all of its libraries to ensure no conflict between them.

Anyone see a parallel to DNS here, by the way ?







<Waits for the inevitable counterexample to back-of-the-envelope idea...>





Author: tony@online.tmx.com.au (Tony Cook)
Date: 1995/06/13
Raw View
Rune Huseby (Rune.huseby@gpi.telemax.no) wrote:

: I know that namespaces was introduced to avoid naming-conflicts across
: libraries, but who defines the namespace names? It is possible that two
: vendors simultanously defines equal namespaces for their libraries, like
: 'ODBCLib' or similar. I would expect that the vendors would try to keep the
: namespace names as short as possible, so programmers don't have to write
: something similar to 'Microsofts_ODBC_library::Connect()'

It's possible for a vendor to define a long name such as
 Microsofts_ODBC_library
and then define a short alias.
--
        Tony Cook - tony@online.tmx.com.au
                    100237.3425@compuserve.com





Author: ellis@allegra.att.com (Margaret Ellis)
Date: 1995/06/14
Raw View
In article <DA379D.Jr6@online.tmx.com.au> tony@online.tmx.com.au (Tony Cook) writes:
>Rune Huseby (Rune.huseby@gpi.telemax.no) wrote:
>
>: I know that namespaces was introduced to avoid naming-conflicts across
>: libraries, but who defines the namespace names? It is possible that two
>: vendors simultanously defines equal namespaces for their libraries, like
>: 'ODBCLib' or similar. I would expect that the vendors would try to keep the
>: namespace names as short as possible, so programmers don't have to write
>: something similar to 'Microsofts_ODBC_library::Connect()'
>
>It's possible for a vendor to define a long name such as
> Microsofts_ODBC_library
>and then define a short alias.
>--
>        Tony Cook - tony@online.tmx.com.au
>                    100237.3425@compuserve.com

Let me add to Tony's observation.  Not only *can* library
implementors *can* use a naming convention for namespaces,
they *should* do so - to reduce the possibility of conflict
with other namespaces.  That is, they *should* use names like
 Microsofts_ODBC_library

Note that use of a namespace (even with a lengthy and
awkward name) is preferable to having to apply a naming
convention to every global name with external linkage in
a library.  The library implementors have only one name
per namespace for which they have to use the possibly
lengthy and awkward name.  And, as Tony notes, providing
an alias is an option.

The only disadvantage of using a namespace right now is
that they are not yet implemented in all C++ compilation
systems, so portability of code that uses namespaces
might be limited.  If the unavailability of a compilation
system supporting namespaces is a problem, define and
adhere to a naming convention.


(Among other things, Martin Carroll and I discuss the
use of naming conventions and namespaces in our new book
"Designing and Coding Reusable C++," just out from
Addison-Wesley.)


Margaret A. Ellis





Author: shepherd@debussy.sbi.com (Marc Shepherd)
Date: 1995/06/10
Raw View
In article 4c3@eccdb1.pms.ford.com, poorman@cc4032.pms.ford.com (Glenn M. Poorman) writes:
:In article <3r79jk$3se@nms.telepost.no>, Rune.huseby@gpi.telemax.no (Rune Huseby) writes:
:|>
:|> I know that namespaces was introduced to avoid naming-conflicts across
:|> libraries, but who defines the namespace names? It is possible that two
:|> vendors simultanously defines equal namespaces for their libraries, like
:|> 'ODBCLib' or similar. I would expect that the vendors would try to keep the
:|> namespace names as short as possible, so programmers don't have to write
:|> something similar to 'Microsofts_ODBC_library::Connect()'
:|>
:|> Will there be some kind of organization that handles the namespace names, like
:|> Microsoft handles OLE 2.0 ID's?
:
>Well I only know what I've read thus far so someone correct me if I'm wrong
>or misinterpreting.
>
>It would be entirely possible for two vendors to use the same name.  Then
>you would have trouble.  But there is no reason to keep the names short so
>you'll probably see names like "Microsofts_ODBC_library".  You can avoid
>constantly having to type the names by using the "using" keyword.  So if
>you have a file that will make several calls to Microsoft's ODBC library,
>you could put:
>
>        using namespace Microsofts_ODBC_library;
>
>up at the top.  Then in the code, you just call:
>
>        Connect();
>
>and it will call the correct function.
>
>Glenn
>

If you encounter a conflict and need to fully-qualify names from
'Microsofts_ODBC_library', you can create an alias like this:

 namespace ODBC = Microsofts_ODBC_library;



Author: Rune.huseby@gpi.telemax.no (Rune Huseby)
Date: 1995/06/08
Raw View
I know that namespaces was introduced to avoid naming-conflicts across
libraries, but who defines the namespace names? It is possible that two
vendors simultanously defines equal namespaces for their libraries, like
'ODBCLib' or similar. I would expect that the vendors would try to keep the
namespace names as short as possible, so programmers don't have to write
something similar to 'Microsofts_ODBC_library::Connect()'

Will there be some kind of organization that handles the namespace names, like
Microsoft handles OLE 2.0 ID's?

-------------------------------------------------------
Rune Huseby, System Engineer        | Cool comment
GPI A/S, Norway                     | still in beta!
E-Mail: rune.huseby@gpi.telemax.no  |






Author: poorman@cc4032.pms.ford.com (Glenn M. Poorman)
Date: 1995/06/09
Raw View
In article <3r79jk$3se@nms.telepost.no>, Rune.huseby@gpi.telemax.no (Rune Huseby) writes:
|>
|> I know that namespaces was introduced to avoid naming-conflicts across
|> libraries, but who defines the namespace names? It is possible that two
|> vendors simultanously defines equal namespaces for their libraries, like
|> 'ODBCLib' or similar. I would expect that the vendors would try to keep the
|> namespace names as short as possible, so programmers don't have to write
|> something similar to 'Microsofts_ODBC_library::Connect()'
|>
|> Will there be some kind of organization that handles the namespace names, like
|> Microsoft handles OLE 2.0 ID's?

Well I only know what I've read thus far so someone correct me if I'm wrong
or misinterpreting.

It would be entirely possible for two vendors to use the same name.  Then
you would have trouble.  But there is no reason to keep the names short so
you'll probably see names like "Microsofts_ODBC_library".  You can avoid
constantly having to type the names by using the "using" keyword.  So if
you have a file that will make several calls to Microsoft's ODBC library,
you could put:

        using namespace Microsofts_ODBC_library;

up at the top.  Then in the code, you just call:

        Connect();

and it will call the correct function.

Glenn

--
-------------------------------------------------------------------------
Glenn M. Poorman   - poorman@cadcam.pms.ford.com
Ford Motor Company - Dearborn, MI