0

Let's say I own a domain called www.john-doe.com. How would I write an appropriate namespace in C#?

Is it Com.John_Doe.<product-name> ?

All I read about C# namespace convetions is that it should use PascalCase. But what about the minus sign? Is it appropriate to write an underscore for it?

John Threepwood
  • 15,593
  • 27
  • 93
  • 149
  • By formatting it that way, it looks as though you are creating an android application space. Namespaces ought to be relevant to the organization of your code and can be whatever is meaningful. – crthompson Apr 08 '14 at 15:08
  • Just pick a convention you like and stick with it – Jonesopolis Apr 08 '14 at 15:10
  • 3
    namespaces in C# have nothing to do with domains or anything like that. That looks like a (very awkward) java convention, which makes no sense whatsoever. if your product is called `My-Product` then you should do `MyProduct.Data` for the data layer, `MyProduct.Model` for the model, `MyProduct.UI` for the UI and so forth. [forget java](http://whyjavasucks.com/). – Federico Berasategui Apr 08 '14 at 15:10
  • You might poke around a popular open source C# project and see how they set up their namespaces: https://json.codeplex.com/ – Troy Carlson Apr 08 '14 at 15:13
  • [Namespace conventions](http://msdn.microsoft.com/en-us/library/vstudio/ms229026.aspx) and [capitalization conventions](http://msdn.microsoft.com/en-us/library/vstudio/ms229043(v=vs.110).aspx) which tell you not to use underscores (the same would go for hyphens), FYI. – Jeff B Apr 08 '14 at 15:38
  • http://msdn.microsoft.com/en-us/library/893ke618(v=vs.71).aspx and another Stack Overflow question here: http://stackoverflow.com/questions/918894/namespace-naming-conventions – stephenbayer Apr 08 '14 at 16:48

2 Answers2

1

According to .NET namespace conventions, you should use pascal casing in namespaces (unless that goes against non-standard casing your company/brand/product uses). And according to capitalization conventions, pascal casing should not include underscores. General naming conventions also tell you to not use hyphen (which will actually produce compiler errors in C# anyway).

Unless Com is intended to be replaced with your company name (from the context, "John Doe" sounds like the company) You should just go with:

JohnDoe.<ProductName>
Jeff B
  • 8,572
  • 17
  • 61
  • 140
  • 1
    Thank you for your explanation! But with `JohnDoe.` one comes in conflict with `www.johndoe.com` using the same namespace? :-( – John Threepwood Apr 08 '14 at 19:16
  • I suppose if you own both website and have projects for both, you'll have an unfortunate namespace collision. Perhaps that would justify using an underscore. – Jeff B Apr 08 '14 at 22:36
0

I think it is personal preference. E.g. my preference is JohnDoe.

y0j0
  • 3,369
  • 5
  • 31
  • 52