473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

About using namespaces

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?

Oct 28 '07 #1
4 1578
tr*********@verizon.net wrote:
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.
Oct 28 '07 #2
tr*********@verizon.net wrote:
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
Oct 28 '07 #3
On Oct 28, 9:23 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
tron.tho...@verizon.net wrote:
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
Where can the FAQ be found?

Nov 2 '07 #4
On 2007-11-02 02:49, tr*********@verizon.net wrote:
On Oct 28, 9:23 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>tron.tho...@verizon.net wrote:
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.
Please do not quote signatures.
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
Nov 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
5
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without...
5
by: EMonaco | last post by:
All, I have a simple C# window app under MyApp namespace it has a class Form1. I've added another class .cs file. Now this class I want to share with many projects, so I figured I'd change this...
4
by: clintonG | last post by:
When using Visual Studio.NET I observe adding a new Web Form may have default References added such as... References o- System o- System.Data o- System.Drawing o- System.Web o- System.XML
3
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
38
by: Arjang | last post by:
http://www.codeproject.com/useritems/CSharpVersusVB.asp
7
by: Peter Kirk | last post by:
Hi, there is a logging service called "log4net". It uses namespaces such as "log4net" and "log4net.Appender". If I am writing my own software, would it be considered bad style to use...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
6
by: Juha Nieminen | last post by:
Whenever one sees example C++ code basically anywhere, be it in a book, in a tutorial in the internet, in an online forum or whatever, I would estimate that at least in 99% of cases one sees the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.