views:

518

answers:

9

Hi there,

I am considering releasing one of my class libraries written in C# as open source. Before doing that, I am trying to do some refactoring so that it meets the demands of the general public :)

I wonder what would be the best namespace schema to use? Basically, I see the following options:

  • namespace MyTool: This just doesn't really look like organized for me. I mean, (almost) all the namespaces in the .NET Framework are prefixed with System so I guess it is not really a standard way to do it.
  • namespace MyOrganization.MyTool: The problem with that there is just simply no "MyOrganization". It is written in my spare time.
  • namespace MyName.MyTool: I would prefer something more humble. I mean really, I don't want to have my name in the namespace.

Now there are a couple of related questions on Stackoverflow already, like this and this, but none of them really answer my question.

Any suggestions?

A: 

If it's open source and there will be contributors I would pick MyTool.

David Vidmar
A: 

If you can afford to change it later, I'd go with MyName.MyTool. If you are the only person writing the tool, you need full credit, and having your name in the namespace doesn't hurt anyone.

If you take on new contributors, you can remove your name from the namespace but only if other people actually made a big contribution. If the majority of work is yours, I'd leave it in.

Dmitri Nesteruk
A: 

I ended up with Idunno.* for a couple of projects (my web site), and SharpSTS.* for the main one (as that's the project name)

blowdart
A: 

MyTool has the problem that names aren't unique; you’re heading for name conflicts. MyCompany.MyTool doesn’t apply in your case if you don’t want to give yourself some label.

I actually rather like the Java convention of reversing the URI associated with the product. For companies, this is the company website. For you – do you have a blog / personal homepage whose address isn’t likely to change soon? Then use the name, with TLD and second-level domain reversed. In my case: net.madrat.MyTool.

I know a few people who use TheirName.MyTool which is fine. Howver, this becomes a problem as soon as there is a second contributor.

Konrad Rudolph
My problem with this approach is have namespaces starting with lowercase letters are not really .NET-like. If I remember correctly, even FxCop bitches about them. On the other hand, Net.MyDomain.MyTool is not really url-like, or is it?
DrJokepu
Yeah...whilst java prescribes using tld.domname.X, (at least when I last touched it 10yrs ago) .NET has a different set of guidelines and conventions that not tied to domain names and this style. http://msdn.microsoft.com/en-us/library/893ke618(VS.71).aspx
Kev
@Kev: I have to say that I don't give a damn about .NET coding guidelines. They are among the worst guidelines ever created. Completely arbitrary and lacking any justification whatsoever. This is very bad for controversial decisions. Although in this case I actually agree that they have a point.
Konrad Rudolph
@Konrad - Have you read http://www.pearsonhighered.com/educator/academic/product/0,3110,0321246756,00.html. Neither arbitrary nor lacking justification, and annotated by Richter, Brumme, Mariani. These guys aren't gonna put their names to unjustifiable 'just because'. Worth a read.
Kev
@Konrad - but I agree in principle with you, arbitrary standards with no rhyme or reason do suck.
Kev
A: 

I would suggest getting a MyOrganization and using it. If you ever take money for the work, you are going to need an entity, and it could protect you from liability. It is fairly easy to set something up.

Or just use a MyOrganization name and create the entity later, but you run the risk of legal name conflicts, etc if you don't set it up first.

JasonS
A: 

You could do MyToolProject.MyTool. Or, you could just come up with some creative name for your "organization" and just have that as what all your future open source projects will be, even if it is just one right now. Then you could have MyCreativeOrgName.MyTool.

BobbyShaftoe
+4  A: 

I'd go with something like:

namespace OpenSourceProjectCodeName.MajorFunctionalArea

For example:

namespace VideoWizardMagicThing.Audio
namespace VideoWizardMagicThing.Audio.Codecs
namespace VideoWizardMagicThing.Video
namespace VideoWizardMagicThing.Video.Codecs

You don't have to go completely mad with namespaces and all you may need is one or two MajorFunctionalArea's. However without knowing how the project is structured or what it does it's hard to say.

HTH
Kev

Kev
A: 

MyOrganization.Technology is still the recommended way to start the namespace with.

I used to have similar problem of namespacing my hobby the projects before. So I've just made up the name for the development group of one (you want to have a short and readable one) and started using it.

However, keep in mind that the usability is still the key. For example, here's is one exception from the rule. Our open source Lokad Shared Libraries are following namespace of the .NET itself (i.e.: System or System.Threading). That's because there are numerous everyday helpers and extensions that should be available for our developers without even noticing that they are leveraging non-BCL code.

It also makes the using declarations look nicer.

Rinat Abdullin
IMHO "invading" the .net official namespace is not a good idea. If the code is 3rd party, it should belong on a 3rd party namespace. Not knowing that some of your code uses external components could lead to lots of hard to debug/find trouble.
Ramiro Berrelleza
Agreed. But this was a compromise. The only assembly that "invades" System namespace is actually used in every single prototype, internal or external project of our company. It is just that useful. Plus it really gets polished by multiple codebases, so there has been no issues with it yet.
Rinat Abdullin
+1  A: 

MyTool sounds pretty much like the project code/brand name?

In that case if you wish to categorise it further without using your organisation or personal name, hook on the industry or problem domain it is meant to address.

VideoEditing.MyTool

Accounting.MyTool

HomeAutomation.MyTool

icelava