• Advertisement

Archived

This topic is now archived and is closed to further replies.

Namespace implementation

This topic is 5121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Namespaces seem to be a good solution for name collision, but no-one uses them. The only namespace I''ve ever seen used is std. I''ve wanted to switch to namespaces, currently all of my functions and globals are prefixed with DS_ (diresoft), and DS:: wouldn''t be too much work. Are namespaces slow? The true general first seeks victory, then seeks battle - Sun Tzu

Share this post


Link to post
Share on other sites
Advertisement
I use namespaces for ALL of my libraries ...

and there is no run-time cost, and almost as little compile time cost (in fact, well partitioned namespaces reduce the size of the global symbol table and can therefore - sometimes - increase compilation lookup speed).

Share this post


Link to post
Share on other sites
and oh yeah, .NET uses them and pretty much requires them ... they even recommend how you should use them (in a .NET enviroment) ...

Share this post


Link to post
Share on other sites
off the top of my head i can think of 4 librarys for C++ which use namespaces;
std as you''ve noted
boost which is a library of very usefull code
corona which is an image loading library
loki which is another code library

and my last large project used a fair few to partition classes and code into logical units (such as networking, utils etc)

so namespaces are certainly very usefull things

Share this post


Link to post
Share on other sites
Namespaces just cause the compiler / linker to decorate and separate the names. They have no runtime costs, at runtime a function is still just an address of some code.

Mark

Share this post


Link to post
Share on other sites
actually, they usuaully have the same runtime cost as LONG NAMES in general ... which is somtimes NONE, and sometimes simply very very little

Share this post


Link to post
Share on other sites
why the hell would namespaces be slow?? Long variable names arent slow, and im sure namespaces would not affect runtime performance. I use namespaces to organize my code, and find them uber handy.

For example, all my graphics go in Reflex::Graphics --
So every time i type in Reflex::Graphics::, the intellisense gets switched on and displays all the classes/functions in the graphics package - below lies a list of the namespaces in my current project....
http://www.reflexengine.net/psamty10/doxygen/namespaces.html

Namespaces are good for much more than name collision, they were designed for code organization

Share this post


Link to post
Share on other sites

  • Advertisement