Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Wikipedia Date: Tue, 07 Jun 2022 08:21:45 -0700 Organization: A noiseless patient Spider Lines: 133 Message-ID: <865ylczegm.fsf@linuxsc.com> References: <20220530195216.0000551a@reddwarf.jmc.corp> <20220531180032.000018e7@reddwarf.jmc.corp> <20220531184340.000065fe@reddwarf.jmc.corp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="8d3b78834a5fcc019414bbade7c1b111"; logging-data="27823"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186NISo3FuHydtltljxEPuARYOh+KbaPrg=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:pO6cC6HzurmKOIHspzD/3frldw8= sha1:sXpOeawREr733PbZqccqZ25ELFo= Xref: csiph.com comp.lang.c++:84573 Manfred writes: > On 6/1/2022 4:58 PM, daniel...@gmail.com wrote: > >> On Wednesday, June 1, 2022 at 10:29:18 AM UTC-4, David Brown wrote: >> >>> And please don't use silly claims of "mental problems". >> >> Agreed >> >>> (Yes, I know others have stopped to that level too - that does not >>> mean it is helpful or appropriate for you to do so also.) >> >> It's almost a trademark of this forum, regrettably. >> >>> And no, the C++ Core Guidelines do /not/ encourage the use of >>> "using namespace std;". >> >> They certainly give it their blessing, from the Guidelines > > Put this way, I find it hard to believe, please give exact > reference of the example below. > >> Example, good >> #include >> #include >> using namespace std; >> >> void use() >> { >> // snipped >> } >> >>> When in doubt, do not use "using namespace std;" at file scope. >> >> Actually, the C++ Core Guidelines specifically state that a ".cpp >> file is a form of local scope", and they appear to have no issue >> with "using namespace std;" in this context. They mention that >> "sometimes a namespace is so fundamental and prevalent in a code >> base, that consistent qualification would be verbose and >> distracting", and they're clearly referring to "std". They bring >> up the risk of name clashes, but suggest it is a manageable risk. > > You should stop extrapolating your conclusions from pieces of > sentences extrapolated from context. I see no basis for this accusation. (Presumably "extrapolated" near the end of the sentence is meant to be "extracted" or "removed" or something along those lines.) > SF.6 (thanks to David for giving this accurate reference) clearly > states its intent from the very beginning, i.e. its title: > > "SF.6: Use using namespace directives for transition, for > foundation libraries (such as std), or within a local scope > (only)" > > Now, instead of giving their blessing to the use of "using > namespace std;" (actually, using directives in general, not only > std), the authors clearly give /constraints/ on where it is > allowed to use this construct: note the (only) part in that > title. This is very different from what you say. > > In particular, they give a motivation for this directive for the > following reasons: > > 1) "transition". This means help dealing with legacy code, not at > all an endorsement to use it with new code. > > 2) "foundation libraries (such as std)". This is probably the > more important part: it means that *if* you are writing a > standard library implementation, then you'd better have "using > namespace std;" in your .cpp files, since most if not all of what > you are writing lives within the std namespace(!) This interpretation is not consistent with other parts of the Core Guidelines. Moreover it seems unlikely that the Core Guidelines would go out of its way to address a point that is relevant /only/ to implementors of the C++ standard library; surely they mean to address a larger audience. A much more likely reading, and also a better fit to other remarks in the Core Guidelines, is that this provision refers to foundation libraries (such as std) as being the namespace opened in a 'using namespace' statement. > 3) "local scope". This is the handle you are trying to hold so > tight on to. In fact, it means that in a limited and controlled > scope, you may use a using directive. This still is in the > perspective of containing namespaces to avoid clashes, but instead > of controlling the imported namespace (std), you make the choice > of controlling your own namespace, by keeping it small. Again, > this is very different from a generic "blessing" to using > namespace std; everywhere. > > About the note "A .cpp file is a form of local scope": here too > you should read beyond the first dozen of letters. If you read > the note in full, you'd see that it is in fact about how large is > the scope in which you are injecting the std namespace: it > explains that it is the N-line count that matters, whether it be a > single function or a combined set of multiple functions "with N > lines of code in total". It does not contradict, but instead it > clearly applies to, the choice of having your own namespace small. I think you're seeing something that isn't there. Nothing in this paragraph is talking about having your own namespaces be small, or suggests that N must be small. On the contrary, the reference to "M functions each containing a using namespace X with N lines of code in total" suggests that N can be reasonably large. The point of the paragraph is that the three situations are equivalent in terms of opportunities for name clashes. Thus if every function in a .cpp file may reasonably have a 'using namespace X;' then it is just as reasonable to put that using statement at the top of the .cpp file instead of in each of the many functions. Neither X nor N has any constraints stated as to what they might be. > Back to the OP, the code that Bonita posted on Wikipedia is > clearly larger than a handful of lines, and anyway it may be meant > to be integrated in a larger program. "using namespace std;" is > still a poor choice, even in the light of the C++ core guidelines. > >> You can of course disagree with that judgement, but then you're >> also disagreeing with Stroustrup and Sutter, not just Bonita. > > No, we are not disagreeing with Stroustrup and Sutter. On the > other hand, it appears that it is you and Bonita who do not > understand properly what they wrote. IMO daniel's conclusions show a more objective reading of the Core Guidelines than your comments above do. Incidentally, before writing any of this, I found a copy of the Core Guidelines online, printed out the Introduction and Source Files sections, and read carefully through all of both sections.