Hi,
I have a suggestion for the C# language team. As you know, a .cs file often contains code in only a single namespace. It would be nice if I could simply say
namespace foo;
class bar
{
...
}
...
instead of
namespace foo
{
class bar
{
...
}
...
}
The default namespace for the file would be changed, replacing the global namespace. This would make things simpler, help to reduce the } } } mess, and save a tab level.
Or is there a reason for why this is not a good idea?
-
-
Here's a reason: In the example below, what is the namespace of class B?
namespace Level1;
class A
{
...
}
namespace Level2
{
namespace Level3
{
class B
{
...
}
}
}
At first glance, it looks like B resolves to Level2.Level3.B, which is wouldn't. It's just cleaner if eveything is clearly outlined. -
It's Level1.Level2.Level3.B obviously. I don't think there's any problem in that. And how many times do you have several top level namespaces in a one file anyway? I have no such files myself.
-
In my limited experience, I've never had more than one namespace in a .cs file. I'm just saying that it might be misconstrued, given my example. If the .cs file was very long, and class B was at the bottom of the file, the reader might miss it. Someone working with command-line compilers and basic text-editors would have a harder time.
-
How will this type of shortcut reconcile in a partial class?
-
I don't even put more than one class/module/whatever in a file. One class per file, use good file names and you'll know exactly where to look for a specific piece of code - at least, that's my experience so far.
-
Anything that increases code readability is a Good Thing. Let the curly braces be your friends.
/Lars.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.