- Home /
Best practices for naming classes in a library.
If I'm developing a script for the Asset Store, and it has a C# class named Item (to use a dummy example), and since Unity doesn't support namespaces, this class name could eventually collide with a class name defined by the user of the asset, or even another Asset Store script included in the same project, right?
If so, should I always name top-level classes using a vendor prefix that makes it more unique (like, e.g., mycompanyItem)? Or what are the conventions and solutions to avoid name clashes with other Asset Store or user scripts?
Answer by Jake.OConnor · Jul 23, 2013 at 03:02 PM
Every programmer and company has their own naming conventions. My company, and I know a lot of other companies as well, often prefix our classes with our abbreviation.
For example, a recent environment manager rewrite that I performed was named BLSEnvironmentManager as to not conflict with HVSEnvironmentManager. This will also group all of your classes together in whatever auto-completion the user's IDE is.
That's what I thought. Looking at the script file names in the asset store, it looks like many people don't care about possible name clashes though.
You are correct. You've also got to take into consideration that about 60% of the stuff that goes into the asset store is crap.
Answer by Jamora · Jul 23, 2013 at 03:00 PM
Unity 4 has limited support for namespaces, as explored in this Answer. I've personally used namespaces in my U4 project and everything has worked fine.
Namespaces look like a gray area with some corner cases. And when you are targeting the Asset Store, I'm inclined to think that they should be ignored in order to avoid surprises and achieve reasonable compatibility.
Your answer