6

Is this OK:

namespace Simple.OData
{
    // Common OData functionality
}

namespace Simple.Data.OData
{
    // The Simple.Data adapter for OData
}

It feels like it might be wrong, but I'm not sure.

Mark Rendle
  • 9,274
  • 1
  • 32
  • 58
  • [This other post](http://stackoverflow.com/questions/918894/namespace-naming-conventions/918913#918913) give you a link with namaspaces naming guidelines. – JPBlanc Sep 05 '11 at 12:54

6 Answers6

7

It's certainly valid - consider System.Xml.Linq and System.Linq. I can't immediately foresee any problems... but that's not to say it's necessarily a good idea.

Personally I prefer Simple.Data.OData over Simple.OData.Data, as I suspect this is primarily aimed at people who are using Simple.Data, but happen to be using OData - not people who are focused on OData. Again, this is like LINQ: System.Xml.Linq is an XML API which plays will with LINQ; it's not a LINQ "provider" as such.

Basically it's the same sort of problem as "I have a converter to convert from type A to type B; do I put it near type A or type B?" - but with namespaces. My experience is that usually more head-scratching goes into thinking of the best thing to do than the problems that would be caused by taking either approach...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Just wondering why originally was not considered "System.Linq.Xml" instead of "System.Xml.Linq", for me it looks more clear – sll Sep 05 '11 at 12:51
  • It probably exists in the `System.Xml` assembly, rather than the `System.Linq` one? – Kieren Johnstone Sep 05 '11 at 12:52
  • @sllev: I was just adding a comment to that effect - fundamentally it's an XML API. You use it when you want to work with XML data - and it happens to work well with LINQ. – Jon Skeet Sep 05 '11 at 12:52
  • @Kieren: Actually it has its own assembly anyway (System.Xml.Linq) – Jon Skeet Sep 05 '11 at 12:53
  • I was hoping for an example of this in the BCL, and had forgotten System.Xml.Linq. Precedent found! Ta. – Mark Rendle Sep 05 '11 at 13:26
5

More correct would be, namespace Simple.OData.Data.

This is because the Data namespace should be grouped with the other classes relating to OData.

If you're thinking along with lines of System.Data, System.Data.SqlClient then it's pretty much because they are a part of the System.Data.dll assembly, and are an integrated part of it. My own implementation of the IDbCommand etc classes live in MyNamespace.SubNamespace.AdoWrapper namespace, if that gives you some context.

In your case, Simple.Data presumably doesn't exist or have much in it, unlike System.Data ..

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
  • +1 but would have sounded cooler as "more correct namespace Simple.OData.Data would be, young Padawan" :p – Kheldar Sep 05 '11 at 12:49
1

Sure it is, if it's semantically correct. Look at how many framework namespaces end in .Design, for example!

AakashM
  • 62,551
  • 17
  • 151
  • 186
0

Yes, it is, but there are some drawbacks.

The namespace is part of the type name. That is, a type named C inside namespace A.B, is actualy named A.B.C.

When you use the using statement, then you are just using a kind of shortcut.

Drawbacks:

I have noticed that sometimes Visual Studio may become little confused, specialy when using namespaces such as System, and others that exist in the .Net framework... in such a way that you must enter the full name of the type.

Miguel Angelo
  • 23,796
  • 16
  • 59
  • 82
0

It might be confusing to some people, but it should not cause any problems. You'll probably need to preprend the namespace though if you type this:

using Simple.Odata;
using Simple.Data.Odata;

Otherwise the compile won't recognise it. There's probably a better structure possible for the thing you're trying to create, but to anwser your question : yes it is ok to do it if you want.

codingbunny
  • 3,989
  • 6
  • 29
  • 54
0

The last part should be dependant on previous part(s) of the namespace. Your adapter has a dependancy with Simple.OData but also with Simple.Data. But since Simple.OData is less generic I'd prefer something like:

using Simple.Data    

namespace Simple.OData.Adapters
{
    // The Simple.Data adapter for OData   
}