Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Adding namespace after the fact

Reply
Thread Tools

Adding namespace after the fact

 
 
snorble@hotmail.com
Guest
Posts: n/a
 
      09-12-2012
Is it better to build code in a namespace from the start? Or is it relatively easy to place it into a namespace after the fact (just put all of the code between the namespace foo { ... })?
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      09-12-2012
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Is it better to build code in a namespace from the start? Or is it
> relatively easy to place it into a namespace after the fact (just
> put all of the code between the namespace foo { ... })?


When you declare something inside a namespace, such as for example:

namespace Foo
{
void bar();
}

you can then implement that by using the namespace qualifier instead of
having to surround your code with a namespace block. In other words, you
can do this:

void Foo::bar()
{
// implementation here
}

This can be practical, especially if you want to be strict about indenting
(or are using an editor that autoindents), as it reduces the amount of
indentation of your code.
 
Reply With Quote
 
 
 
 
Öö Tiib
Guest
Posts: n/a
 
      09-12-2012
On Wednesday, September 12, 2012 5:28:39 AM UTC+3, (unknown) wrote:
> Is it better to build code in a namespace from the start? Or is it relatively easy to place it into a namespace after the fact (just put all of the code between the namespace foo { ... })?


Namespaces provide way to systematically qualify the names with
additional context, sub-context etc. Within context then you can write
the code using very short (unqualified) names for things in same
context. There are lot of ways how to import, alias and typedef names
from other contexts to keep everything short to the point within a
context. As result using namespaces systematically from scratch your
code is short and elegant.

When you write without namespaces first (with maybe add them later) then
you can not have names that make sense only within small context (like
"filter", "loader", "access", "range", "logic"). That very likely does
not even compile to use so common names in global namespace. Therefore
you qualify the names immediately somewhat anyway like
"network_service_loader". Later you add namespaces and get abominations
like "device_network::service::network_service_load er". The whole point
of having the namespaces in language was actually lost as result. It
will feel like converting from C to C++ by replacing 'malloc' with 'new'
and 'struct' with 'class' pointlessly.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to mix-in __getattr__ after the fact? dhyams Python 6 11-08-2011 05:58 AM
AJAX "After the Fact" Jonathan Wood ASP .Net 11 05-17-2008 12:51 PM
How to enable AJAX in ASPX page after the fact Cirene ASP .Net 5 04-30-2008 02:12 PM
dual boot after the fact Lynn McGuire Windows 64bit 5 06-15-2005 12:36 AM
Possible to surround a table with a cell...after the fact? comcast HTML 5 03-03-2004 11:08 PM



Advertisments