Declared namespaces in small projects?

D

Davej

Every time you create a new project or class in VS2010 you are
presented with an outline of code with a declared namespace. Does it
make sense to always delete these namespaces in small projects which
consist of only a few classes or is there any advantage in keeping
them? Thanks.
 
A

Arne Vajhøj

Every time you create a new project or class in VS2010 you are
presented with an outline of code with a declared namespace. Does it
make sense to always delete these namespaces in small projects which
consist of only a few classes or is there any advantage in keeping
them?

Your hello world program will not stop working because
you remove it.

But you should always use namespace in a more serious
piece of code. And you should start getting good habits
even with hello world, so I think you should keep
them.

MS recommendation:

http://msdn.microsoft.com/en-us/library/ms229050.aspx

<quote<
Do not define types without specifying their namespaces.

Types that are not assigned a namespace are placed in the global
namespace. Because they are not in a feature-specific namespace, types
in the global namespace are difficult to find using development tools.
Additionally, name collisions in the global namespace cannot be
resolved. For more information, see Names of Namespaces.
</quote>

http://msdn.microsoft.com/en-us/library/ms229026.aspx

may also be relevant.

Arne
 
D

Davej

Every time you create a new project or class in VS2010 you are
presented with an outline of code with a declared namespace. Does it
make sense to always delete these namespaces in small projects which
consist of only a few classes or is there any advantage in keeping
them?

Your hello world program will not stop working because
you remove it.

But you should always use namespace in a more serious
piece of code. And you should start getting good habits
even with hello world, so I think you should keep
them.
[...]

Ok, consider a simple console program with a main and three classes.
Would they all be placed in the same namespace? Thanks.
 
A

Arne Vajhøj

Every time you create a new project or class in VS2010 you are
presented with an outline of code with a declared namespace. Does it
make sense to always delete these namespaces in small projects which
consist of only a few classes or is there any advantage in keeping
them?

Your hello world program will not stop working because
you remove it.

But you should always use namespace in a more serious
piece of code. And you should start getting good habits
even with hello world, so I think you should keep
them.
[...]

Ok, consider a simple console program with a main and three classes.
Would they all be placed in the same namespace?

That depends on whether they logical belong in the
same namespace or not.

They may very well do.

Arne
 
M

Matt

On 2/4/2012 4:46 PM, Davej wrote:
Your hello world program will not stop working because
you remove it.
But you should always use namespace in a more serious
piece of code. And you should start getting good habits
even with hello world, so I think you should keep
them.
[...]

Ok, consider a simple console program with a main and three classes.
Would they all be placed in the same namespace? Thanks

To me, it depends simply on whether or not you will ever reuse the
three
classes. If you do, you probably want to put them in a separate
library with
its own namespace, rather than copying and pasting the code from one
project to another.

If, on the other hand, they are simple utility classes that are purely
intended
for this one program, I'd say they belong in the same namespace and
the default
is fine.

Either way, why remove code that isn't hurting you any? Seems like a
lot of
effort for no gain.

Matt
 

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