C# Naming Conventions – Namespace and Class Naming for Libraries

cnamespacenaming

I'm building libraries with various small utility functions in C#, and trying to decide on a namespace and class naming convention. My current organization is like this:

Company
Company.TextUtils
    public class TextUtils {...}
Company.MathsUtils
    public class MathsUtils {...}
    public class ArbitraryPrecisionNumber {...}
    public class MathsNotation {...}
Company.SIUnits
    public enum SISuffixes {...}
    public class SIUnits {...}

Is this a good way to organize the namespace and classes, or is there a better way? In particular it seems like having the same name in the namespace and class name (e.g. Company.TextUtils namespace and TextUtils class) is just duplication and suggests that the scheme could be better.

Best Answer

It's very difficult to determine how effective your naming strategy is in isolation from the rest of your code.

The namespace should give some idea where it fits in the broad structure of your codebase, and the class name would usually describe what sort of functionality or concept it represents within that area.

Caveats aside, in your specific example, if you're likely to have a lot more 'Util' type classes, I would consider putting them under Company.Utils.Maths etc. That way if you need to add functionality that's common to multiple utility areas, you already have a natural location for it.

Related Topic