Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 21st, 2005, 2:22 PM   #1
BrinyCode
Newbie
 
Join Date: Nov 2005
Posts: 11
Rep Power: 0 BrinyCode is on a distinguished road
Question "Namespaces" what are they for & why...

I've been hearing a lot about "Namespaces" here and online tutors so what exactly are they for & why? They sound kind of abstract. What's the best way to visualize them for?
BrinyCode is offline   Reply With Quote
Old Nov 21st, 2005, 2:30 PM   #2
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4 Ghost is on a distinguished road
Think of a Namespace as a name for that file for the code to reffer itself to with out using file names. Best Answer I have for you, sorry.
Ghost is offline   Reply With Quote
Old Nov 21st, 2005, 3:37 PM   #3
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4 Klarre is on a distinguished road
If you are working with two (or more) external libraries, and they both have a class named for example Vector3, and you want to create a Vector3 object. Which constructor do your object use then? A conflict will appear.
The solution to this is to use namespaces, so the consturctors got different names, and wont collide.
Physics::Vector3 myVector;
Renderer::Vector3 myVector2;
Klarre is offline   Reply With Quote
Old Nov 21st, 2005, 3:44 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
A nice, previous treatement on the forum can be found here .
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 3:59 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 927
Rep Power: 4 lectricpharaoh will become famous soon enough
The simple answer is that a namespace is a context in which symbols (names of variables, functions, classes, etc) reside. It is similar to how you might refer to your house as 'home', and I refer to mine as 'home'. Yet when you say 'home', I don't think you're talking about my house, and vice versa. In C++ syntax, we would refer to those symbols as BrinyCode::home and lectricpharaoh::home. The full name allows us to avoid the ambiguity that would otherwise occur. C++ namespaces are a mechanism for resolving such ambiguities in code. Other languages have their own mechanism, such as packages in Java, that perform pretty much the same job. Some languages, like C, don't have any such mechanism, which means you're more likely to run into naming conflicts.

For a more comprehensive discussion, see the link that DaWei posted.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Nov 21st, 2005, 5:18 PM   #6
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4 Ghost is on a distinguished road
They beat my answer to $#%....much better job explain guys, good work =)
Ghost is offline   Reply With Quote
Old Nov 22nd, 2005, 12:12 AM   #7
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
very informative indeed.

p.s. @ ghost, animated avatars are not allowed. even though they're cool.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Nov 22nd, 2005, 5:33 PM   #8
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4 Ghost is on a distinguished road
are they really not allowed? that is weird and kind of sad, whats the reasoning?
Ghost is offline   Reply With Quote
Old Nov 22nd, 2005, 6:12 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It's simple, really, Ghost. Some animated avatars may be overly distracting. Others could conceivably trigger epileptic reactions. It's best not to ask the moderators to decide where to draw those lines. It's easier to just draw the line at "none". Shoot, I had one, myself. I'm doing okay without it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 22nd, 2005, 6:36 PM   #10
D-Ferg27
Programmer
 
D-Ferg27's Avatar
 
Join Date: Oct 2005
Posts: 49
Rep Power: 0 D-Ferg27 is on a distinguished road
Quote:
Originally Posted by DaWei
It's simple, really, Ghost. Some animated avatars may be overly distracting. Others could conceivably trigger epileptic reactions. It's best not to ask the moderators to decide where to draw those lines. It's easier to just draw the line at "none". Shoot, I had one, myself. I'm doing okay without it.
whoa i didn't even notice his thing was animated.
__________________
Dylan Ferguson hence the nickname D-Ferg

Got an IPod?
Use ManagePod
All the cool kids are doing it.
D-Ferg27 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC