Connecting Tech Pros Worldwide Forums | Help | Site Map

About using namespaces

tron.thomas@verizon.net
Guest
 
Posts: n/a
#1: Oct 28 '07
If I remember correctly, in one of his books, Scott Meyers suggests
putting code into a custom namespace rather, and here I might be
paraphrasing, "polluting the global namespace" with type definitions
and such.

Assuming this is a good idea, I'm wondering about what happens when so
many people do the following:

using namespace std;

It seems like such a statement will bring a lot of stuff into the
global namespace, and a lot of it won't be used at all. Most people
only make use of a small portion what contained in the std namespace.

I'm wondering if it isn't better to only declare what someone wants to
use such as:

using std::vector;
using std::cout;

What kind of difference can it make to use either approach for
promoting items for a specific namespace for use in global scope?


Daniel T.
Guest
 
Posts: n/a
#2: Oct 28 '07

re: About using namespaces


tron.thomas@verizon.net wrote:
Quote:
If I remember correctly, in one of his books, Scott Meyers suggests
putting code into a custom namespace rather, and here I might be
paraphrasing, "polluting the global namespace" with type definitions
and such.
>
Assuming this is a good idea, I'm wondering about what happens when so
many people do the following:
>
using namespace std;
>
It seems like such a statement will bring a lot of stuff into the
global namespace, and a lot of it won't be used at all. Most people
only make use of a small portion what contained in the std namespace.
>
I'm wondering if it isn't better to only declare what someone wants to
use such as:
>
using std::vector;
using std::cout;
>
What kind of difference can it make to use either approach for
promoting items for a specific namespace for use in global scope?
If "using namespace /X/" is contained within an individual translation
unit (a .cpp file) then it is a rather local "pollution" that can be
easily changed (assuming you aren't writing .cpp files that are
thousands of lines long.)

However putting using declarations or definitions in header files have a
much wider effect.
Victor Bazarov
Guest
 
Posts: n/a
#3: Oct 28 '07

re: About using namespaces


tron.thomas@verizon.net wrote:
Quote:
If I remember correctly, in one of his books, Scott Meyers suggests
putting code into a custom namespace rather, and here I might be
paraphrasing, "polluting the global namespace" with type definitions
and such.
>
Assuming this is a good idea, I'm wondering about what happens when so
many people do the following:
>
using namespace std;
>
It seems like such a statement will bring a lot of stuff into the
global namespace, and a lot of it won't be used at all. Most people
only make use of a small portion what contained in the std namespace.
>
I'm wondering if it isn't better to only declare what someone wants to
use such as:
>
using std::vector;
using std::cout;
>
What kind of difference can it make to use either approach for
promoting items for a specific namespace for use in global scope?
I believe there is a FAQ on that. See 27.5.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


tron.thomas@verizon.net
Guest
 
Posts: n/a
#4: Nov 2 '07

re: About using namespaces


On Oct 28, 9:23 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
tron.tho...@verizon.net wrote:
Quote:
If I remember correctly, in one of his books, Scott Meyers suggests
putting code into a custom namespace rather, and here I might be
paraphrasing, "polluting the global namespace" with type definitions
and such.
>
Quote:
Assuming this is a good idea, I'm wondering about what happens when so
many people do the following:
>
Quote:
using namespace std;
>
Quote:
It seems like such a statement will bring a lot of stuff into the
global namespace, and a lot of it won't be used at all. Most people
only make use of a small portion what contained in the std namespace.
>
Quote:
I'm wondering if it isn't better to only declare what someone wants to
use such as:
>
Quote:
using std::vector;
using std::cout;
>
Quote:
What kind of difference can it make to use either approach for
promoting items for a specific namespace for use in global scope?
>
I believe there is a FAQ on that. See 27.5.
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Where can the FAQ be found?

=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
 
Posts: n/a
#5: Nov 2 '07

re: About using namespaces


On 2007-11-02 02:49, tron.thomas@verizon.net wrote:
Quote:
On Oct 28, 9:23 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
>tron.tho...@verizon.net wrote:
Quote:
If I remember correctly, in one of his books, Scott Meyers suggests
putting code into a custom namespace rather, and here I might be
paraphrasing, "polluting the global namespace" with type definitions
and such.
>>
Quote:
Assuming this is a good idea, I'm wondering about what happens when so
many people do the following:
>>
Quote:
using namespace std;
>>
Quote:
It seems like such a statement will bring a lot of stuff into the
global namespace, and a lot of it won't be used at all. Most people
only make use of a small portion what contained in the std namespace.
>>
Quote:
I'm wondering if it isn't better to only declare what someone wants to
use such as:
>>
Quote:
using std::vector;
using std::cout;
>>
Quote:
What kind of difference can it make to use either approach for
promoting items for a specific namespace for use in global scope?
>>
>I believe there is a FAQ on that. See 27.5.
Please do not quote signatures.
Quote:
Where can the FAQ be found?
Normally it can be found at http://www.parashift.com/c++-faq-lite/
though here have been some DNS problems so if that does not work try
http://www.coders2020.com/cplusplus-...ned/index.html

--
Erik Wikström
Closed Thread