Re: Do you put functions in the global namespace? Other than main()
From: Steven T. Hatton (susudata_at_setidava.kushan.aa)
Date: 03/27/04
- Next message: Gordon Burditt: "Re: Possible way to overcome the file size limit"
- Previous message: John Harrison: "Re: operator overload"
- In reply to: Nick Hounsome: "Re: Do you put functions in the global namespace? Other than main()"
- Next in thread: Steven T. Hatton: "Re: Do you put functions in the global namespace? Other than main()"
- Reply: Steven T. Hatton: "Re: Do you put functions in the global namespace? Other than main()"
- Reply: Nick Hounsome: "Re: Do you put functions in the global namespace? Other than main()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 27 Mar 2004 05:56:01 -0500
Nick Hounsome wrote:
> This is just a specific example of the more general concept of
> hierarchical naming> 'authorities' -
Yes, I understand this. I actually run my own DNS server. This is clearly
what the intent of this paragraph from the Standard:
"It is undefined for a C++ program to add declarations or definitions to
namespace std or namespaces within namespace std unless otherwise
specified. A program may add template specializations for any standard
library template to namespace std. Such a specialization (complete or
partial) of a standard library template results in undefined behavior
unless the declaration depends on a user-defined name of external linkage
and unless the specialization meets the standard library requirements for
the original template. 163)"
> If you control a certain domain it means that you can
> ensure that there
> are no name clashes in that domain. One way of doing this is to create
> suddomains
> and delegate naming authority for these recursively.
Similar to the X-500 naming hierarchy.
> The standard is (almost) flat because the standard is created/agreed as a
> whole rather
> than having different parts being standardized independently. The only
> sub-namespace
> (that I am aware of) is rel_ops which exists for a completely different
> reason and should
> probably never have been created - the amount of application coding saved
> is typically
> little or none as most apps seem to get by without even needing the
> operators and
> writing your own is trivial.
The method used to form subsets of symbols within the STL is the use of
headers. The same categorization could have been achieved using a deeper
namespace hierarchy. The use of two independent means of grouping is a bit
disconcerting, but I will live with it until an acceptable alternative is
available.
> All the companies that I have ever worked for sell programs rather than
> libraries so I
> don't usually bother with namespaces. In principle I could reuse code from
> other projects
> or even within a project but I have never found name clashes to be a
> problem and there
> is never a company naming authority anyway.
Can you download, say, Xerces C, add it to your IDE's configuration and
immediately brows the available symbols in the Xerces headers through some
lookup tool in the IDE? Could you do the same thing predictably for any
C++ project on Sourceforge?
> Nowadays I don't even use namespaces for enums and free functions as it is
> much more convenient
> to make them enums and static functions in a class.
My inclination is to combine the use of namespaces with the approach you
have described, with this caveat: Stroustrup makes the point that functions
which do not need access to member data of a class 'should' not be members
of the class. An example is a binary operator such as '+', or '-' which
returns a value based on two arguments of compatable types. I feel
obligated to adhere to this advice, but find it a bit contrary to my
notions of compartmentalization.
My first real job was as a missile guidance electronic specialist.
Everything was in an identifiable compartment, usually within a larger
compartment. Components had clearly defined, and isolated interfaces to
other components. I guess that had a longlasting impact on my thinking.
There's also something to be said for the approach to mathematical syntax
which says a+ is an operator that takes b as an argument to produce a+b. I
haven't given that extensive consideration in the context of C++, but it
seems worth comparing to the use of operators in the language. It also has
little to do with namespaces.
-- p->m == (*p).m == p[0].m
- Next message: Gordon Burditt: "Re: Possible way to overcome the file size limit"
- Previous message: John Harrison: "Re: operator overload"
- In reply to: Nick Hounsome: "Re: Do you put functions in the global namespace? Other than main()"
- Next in thread: Steven T. Hatton: "Re: Do you put functions in the global namespace? Other than main()"
- Reply: Steven T. Hatton: "Re: Do you put functions in the global namespace? Other than main()"
- Reply: Nick Hounsome: "Re: Do you put functions in the global namespace? Other than main()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|