Namespaces

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Namespaces

Post by Ginto8 »

What is the purpose of a namespace, and why use it? I know there's namespace std in the STL, and Nehe's new tutorials have a namespace nehe, but what do you actually use it for?
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Namespaces

Post by LeonBlade »

A namespace is basically making things neat... it's a container if you will...
The namespace you are in is just a way to keep all your classes organized under something bigger.

Commands are in a function, functions are in classes, classes are in a namespace.
There's no place like ~/
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Namespaces

Post by MarauderIIC »

If you're working on a large project it prevents function/class name overlap, theoretically, too. I've never used one in a C++ project, although I use them in C# on separate modules with namespaces of "Appname.Business" (contains classes that do calculations on data), "Appname.Data" (contains classes that interface with database), "Appname.Utility" (contains secure redirect fn)...
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
BOMBERMAN
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Wed Jan 14, 2009 5:00 pm

Re: Namespaces

Post by BOMBERMAN »

The namespace concept appears in order to control the scope of names to allow the same names to be used without conflicts - Text from the book "Programming in c++"
My english sucks!
User avatar
sparda
Chaos Rift Junior
Chaos Rift Junior
Posts: 291
Joined: Tue Sep 23, 2008 3:54 pm

Re: Namespaces

Post by sparda »

Namespaces are used to avoid name clashes between existing libraries, and anything you might write (in its most basic use).

I've seen it used in a modular programming paradigm as well.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Namespaces

Post by Ginto8 »

BOMBERMAN wrote:The namespace concept appears in order to control the scope of names to allow the same names to be used without conflicts - Text from the book "Programming in c++"
I thought that might have been what it was... Thanks for clarifying. :)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply