Reduce Namespace Block Nesting

Problem
You want to know how to apply namespacing in your code.

Solution
You should avoid using namespace blocks. Instead, you should use loose, disjointed namespace blocks and the dot notation.

Comments
The reason for this best practice is to prevent statements that are indented too far to the right and require horizontal scrolling. Plus, the majority of C# developers will find nested namespacing odd and unconventional.

Example
The following code defines a type named Logger in the AutomatedQa.Utils namespace.

// Don't do this.
namespace AutomatedQa
{
    namespace Utils
    {
        public class Logger
        {
            ...
        }
    }
}

// Instead do this.
namespace AutomatedQa.Utils
{
    public class Logger
    {
        ...
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s