views:

152

answers:

5

Hello,

I have a third party SDK in C# which has class names like this:

com.companyname.productclass.enterprise.productname.sdkname.namespace
com.companyname.productclass.enterprise.productname.sdkname.namespace.objects
com.companyname.productclass.enterprise.productname.sdkname.namespace.objects.fields
com.companyname.productclass.enterprise.productname.sdkname.namespace.objects.fields.data
com.companyname.productclass.enterprise.productname.sdkname.namespace.security

... and so on.

Is there some point to this that I'm missing? Or is just a matter of coding style?


The SDK is rather more verbose than seems necessary in several ways, resulting in multi-thousand line .cs files, so I'm willing to accept the person(s) that wrote it have a different coding style to what I'm used to (or were being paid per byte :D )

+7  A: 

The point is to avoid naming conflicts. For example, if I created a class library with an "objects" namespace as in

com.davidstratton.productclass.enerprise.productname.sdkname.objects

it could exists side-by-side with the other classes.

It may seem like overkill, but keep in mind the days of "dll hell" that plagued development in pre .Net days. To companies could (and did) product classes with the same name, so that installing one application could break another application. One of the design goals of .Net was to avoid this.

The naming convention you are asking about is actually specified in the Class Design guidelines as documented here: http://msdn.microsoft.com/en-us/library/ms229048.aspx.

Edit - Added

My statement above is incorrect in saying that this is in the "official guidelines". I'm not sure where I saw the "com.companyname.blah.foo.bar" naming recommendation, but it's not in the current definition or older definitions that I can find. I must have imagined reading it somewhere.

So I officially agree with everyone who said it's overkill.

David Stratton
I can see namespace clashes might be an issue. but surely `productname.objects` would suffice for that? or `productname.sdkname.objects` at most? 9 heirachical levels of namespace seems beyond paranoid to me!
Colin Pickard
It could be overkill. The depth in your example seems extreme to me, but it does follow the "official" guidelines.
David Stratton
What 'official' guidelines are they then? The MS ones are not THAT deep. This example is beyond necessary.
Wim Hollebrandse
I'm looking.... Way back when in the .Net 1.0 days, i saw documentation stating that you should use the "com.companyname..." syntax. However, that may have just been in a book and not the official guidelines from Microsoft. Unfortunately, I can't find a corresponding section in the MSDN library for .Net 1.0.
David Stratton
+1  A: 

That looks over the top, but you should always include a namespace so that isn't going to conflict with other ones (e.g. based on the company's domain) - this is especially important with an SDK as I guess the intention is that it will be used in a wide variety of contexts.

If you don't then you'll end up potentially regretting it eventually and have a refactoring job ahead to fix it. Using statements at the top of files isn't a big burden really.

FinnNk
+5  A: 

Overly verbose. It wouldn't surprise me if somehow this SDK was a port of a Java codebase or has been mainly written by Java developers.

The namespace convention is definitely not in line with general best practices and Microsoft recommendations.

See: Namespace Naming Guidelines

Wim Hollebrandse
Yes I believe many of this company's products are in Java. Thanks for the link, that reassures me that I'm using a sensible convention in my own code!
Colin Pickard
+1  A: 

You should read the post (also on stackoverflow) about the clever programmer who created a global variable named, "int." That'll answer this question in a hurry!

inked
Have you got a link to this post?
David Stratton
I've just been looking too, and I can't see it. Maybe it's been deleted?
Colin Pickard
Found it. http://stackoverflow.com/questions/1642421/vbscipt-call-builtin-functions-shadowed-by-global-variables
David Stratton
+1  A: 

It's to prevent class naming conflicts, which can occur frequently when you're using multiple libraries in your project.

A good example within the .NET framework itself: there is an Image class in the System.Web.UI.WebControls namespace, and an Image class in the System.Drawing namespace. Without namespaces, these classes would conflict with one another.

Tim S. Van Haren