By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,670 Members | 1,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,670 IT Pros & Developers. It's quick & easy.

[Proposal] Short namespace syntax

P: n/a
Why do we always need braces around namespaces?

It frightens me that even a simply class looks so much nested and
complicated due to this verbose namespace syntax. It also unnecessarily
increases the indentation level of *every* file. The funny thing is that I
cannot imagine one single situatation where it *could* be useful to have
more than one namespace per file.

Why not simply allow (additional to the existing syntax) simply this:

namespace MyCompany.MyProduct;

This short namespace declaration, if present, must appear only once per file
and above all other statements in the file. If someone sees this syntax he
can be sure that this file has only one namespace.
Nov 16 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Because you can multiple different namespaces?

"cody" <de********@gmx.de> wrote in message
news:ul*************@tk2msftngp13.phx.gbl...
Why do we always need braces around namespaces?

It frightens me that even a simply class looks so much nested and
complicated due to this verbose namespace syntax. It also unnecessarily
increases the indentation level of *every* file. The funny thing is that I
cannot imagine one single situatation where it *could* be useful to have
more than one namespace per file.

Why not simply allow (additional to the existing syntax) simply this:

namespace MyCompany.MyProduct;

This short namespace declaration, if present, must appear only once per
file and above all other statements in the file. If someone sees this
syntax he can be sure that this file has only one namespace.

Nov 16 '05 #2

P: n/a
then, you provide meaning to the file itself. The language has no
understanding of the notion of a file. All of the files in the project can
be viewed, from the standpoint of the compiler, as belonging to a single
long stream of text.

This is nearly always easier from the standpoint of the tools. The language
is more elegant and it is easier to refactor the code.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"cody" <de********@gmx.de> wrote in message
news:ul*************@tk2msftngp13.phx.gbl...
Why do we always need braces around namespaces?

It frightens me that even a simply class looks so much nested and
complicated due to this verbose namespace syntax. It also unnecessarily
increases the indentation level of *every* file. The funny thing is that I
cannot imagine one single situatation where it *could* be useful to have
more than one namespace per file.

Why not simply allow (additional to the existing syntax) simply this:

namespace MyCompany.MyProduct;

This short namespace declaration, if present, must appear only once per
file and above all other statements in the file. If someone sees this
syntax he can be sure that this file has only one namespace.

Nov 16 '05 #3

P: n/a
>It also unnecessarily
increases the indentation level of *every* file.


You're not forced to indent the class inside the namespace block you
know.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4

P: n/a
then, you provide meaning to the file itself. The language has no
understanding of the notion of a file.


The using and extern alias directives are already scoped to a single
file.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #5

P: n/a
> >It also unnecessarily
increases the indentation level of *every* file.


You're not forced to indent the class inside the namespace block you
know.


I do not have to but it looks even more stupid if I have braces and do not
ident them, at the end they are still there.
However if I do not ident them visual studio does it for me.
Nov 16 '05 #6

P: n/a
> Because you can multiple different namespaces?

Did you really read my post? That was exactly my point: I know no case where
someone would actually need more than one namespace per file. In the rare
case someone actually does, the old namespace syntax can still be used.
Nov 16 '05 #7

P: n/a
>>then, you provide meaning to the file itself. The language has no
understanding of the notion of a file.


The using and extern alias directives are already scoped to a single
file.


Which defeats Nick's point as a whole :)
Since using directives and namespaces declarations are very related they
should also be treated the same.
Nov 16 '05 #8

P: n/a
> then, you provide meaning to the file itself. The language has no
understanding of the notion of a file. All of the files in the project
can be viewed, from the standpoint of the compiler, as belonging to a
single long stream of text.


If multiple *.cs files are concatenated it won't compile because the using
directives can only appear a the beginning of the file.
Also the preprocessor first has to remove #define statements which are also
scoped per file and resolve #if #else clauses.

So even if there should be a problem with backward compatibility that the
new syntax allows namespaces declarations without braces, the preprocessor
could insert the braces automatically
Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.