PC Review


Reply
Thread Tools Rate Thread

Declared namespaces in small projects?

 
 
Davej
Guest
Posts: n/a
 
      4th Feb 2012
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.
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      7th Feb 2012
On 2/4/2012 4:46 PM, Davej wrote:
> 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

 
Reply With Quote
 
Davej
Guest
Posts: n/a
 
      8th Feb 2012
On Feb 7, 3:59*pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> On 2/4/2012 4:46 PM, Davej wrote:
>
> > 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.

 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      8th Feb 2012
On 2/8/2012 11:43 AM, Davej wrote:
> On Feb 7, 3:59 pm, Arne Vajhøj<a...@vajhoej.dk> wrote:
>> On 2/4/2012 4:46 PM, Davej wrote:
>>
>>> 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



 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      8th Feb 2012
On Feb 8, 9:43*am, Davej <galt...@hotmail.com> wrote:
> On Feb 7, 3:59*pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>
>
>
>
>
> > On 2/4/2012 4:46 PM, Davej wrote:

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


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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:34 PM.