Path: csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Kaz Kylheku Newsgroups: comp.programming Subject: Re: Here is why C++ and C are bad... Date: Tue, 29 Dec 2015 21:20:17 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 59 Message-ID: <20151229131302.548@kylheku.com> References: NNTP-Posting-Host: OGJi3KNpFOhM58UHZwXj0w.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: slrn/pre1.0.0-18 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.programming:6074 On 2015-12-29, Richard Heathfield wrote: > On 26/12/15 00:54, Ramine wrote: >> >> Hello, >> >> I was working on a project in C++, but i have encountered >> a problem with the language that we call C++, this problem >> is inherent to C++ and C, here is a small example that >> shows the problem: >> >> === >> >> #include >> using namespace std; > > This is a very bad idea. The *whole point* of namespaces is to avoid > name clashes. What you should do (and indeed what you *do* do) is to use > the std:: prefix for symbols that you pull in from the std namespace. So > you don't need using namespace std at all! Just remove it. Indeed, "using namespace std" means "bring into my namespace here all symbols in std, current and future, vendor-specific and standard". It's a transition mechanism for programmers who want namespaces to go away and deal with clashes, or who want to do a quick and dirty port of pre-namespace C++ code to namespaces. Of course, the "using namespace" mechanism is perfectly useful, if namespaces are sanely designed by someone who pins down the exact contents. For instance: namespace foo_api { // everything int a, b, c, d, e; void f(), g(), h(); // Only a and f existed in the 1.0 API namespace v1_0 { using foo_api::a; using foo_api::f; } // 2.0 has all of 1.0 plus c, and g. namespace v2_0 { using namespace foo_api::v1_0; using foo_api::c; using foo_api::g; } // 3.0 has everything. // (In the future it won't!) namespace v3_0 { using namespace foo_api; } } Now you can do "using namespace foo_api::v1_0" with the confidence that you're getting an exact, documented set of identifier which shall never change.