[Proposal] Short namespace syntax

C

cody

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.
 
N

Nick Malik [Microsoft]

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.
 
M

Mattias Sjögren

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
 
M

Mattias Sjögren

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
 
C

cody

It also unnecessarily
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.
 
C

cody

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.
 
C

cody

then, you provide meaning to the file itself. The language has no
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.
 
C

cody

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top