Skip to main content
GameDev.net gamedev.net
🔒 Locked

namespaces

Started by Khaos Nov 2, 2004 at 2:57 PM 2 replies 350+ views
Original Post
Khaos
Khaos
Let us consider the following C# program:

namespace Huge
{
  class Talk
  { }
  class DoNOT
  { }
}
-----
namespace KITTen
{
  class Moreover
  { }
  class DoNOT
}
-----

using KITTen;
using Huge;

DoNot.Method();

Would that code simply cause an error? In other words, if you have two namespaces with the same class name, and you use the "using" keyword for both of them, and try to access a class, how will it know of which namespace it will call? I am guessing this results in an error, correct? Also, if you have a group of people working on a project, is it the point of namespaces to group code into sections like ByMike, ByTim, or ByGraphics, BySoundCrew, et cetera? That way each group or person can operate in their own namespace without ever worrying about names getting mixed up? How would you avoid the *possible* error that was my original question, if it is an error? Any namespace tips in general to share? Thank you.
twanvl
twanvl
Your code will result in an error. IMHO using namespaces like "byTwanvl" is not a good idea, when you want to use a certain function/class you will have to find out who wrote it. It is much better to make namespaces based on modules in the project "soundEngine", "graphicsEngine.billboards", etc.
Mykre
Mykre

You need to prefix the code with the namespace if there is more then one namespace with the same member.

I always use the namespaces to reflect sections of relevant code, like

ircomm.chatserver.communications
ircomm.chatserver.informationstore
ircomm.configuration.xmlinifile
Xai
Xai
The "who made it" namespace organization is Microsoft's recommended way to organize the TOP LEVEL namespace ... into work by different companies or LARGE divisions inside of companies ... the reason is that this way, when you cannot communicate with each other to decide on namespaces, the fact that you have a, hopefully, unique top level company name will solve this problem for you ...

for namespaces under the top level, you should almost always organize by functionality, not by who or where it was made ... the occasional exception is, if you have say 3 projects in your company that don't talk enough, your second level might be the "project" group ...

So some examples:

System.Xml.XmlDocument
Microsoft.IDontRemember.WhatTheyHave.Here

// DataDynamics is the company that makes the ActiveReports reporting package
DataDynamics.ActiveReports.ActiveReport

// goldleaf is my last company
Goldleaf.Logging.Logger
Goldleaf.Logging.DS.SqlServer.LogEntryTypeResolverDS

// xainosis is my personal project "company"
Xainosis.Commons.StringUtils
Xainosis.CSFG.GameObjects.Fleet
// (CSFG is my "crappy sci-fi game" project)


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.