Category talk:C++

From Rosetta Code

std namespace

Is there some reason none of the code examples include the line: <lang C++>using namespace std;</lang>

It'd make things a lot shorter and more readable. MagiMaster 22:53, 24 May 2011 (UTC)

It's a simple style choice. Some people like to be explicit in case other namespaces have similarly named functions. You can add the line for new examples but I don't think it's worth it to change the other ones. You could also try to organize the C++ community a la J/HouseStyle. --Mwn3d 03:45, 25 May 2011 (UTC)
Probably because I wrote more than a few of them (C++ is my day job, so sometimes I have the skill, if I can find the time), and I don't like the line; I've hit namespace conflicts with it, and so I avoid them by keeping things explicit. I'm also a creature of habit; even if a safeguard (such as not using using namespace std) isn't necessary in a given case, I'll use it anyway, so I haven't erred in missing it, and so I can habitually avoid the conflict in the future. However, as Mwn3d noted, it's stylistic, and not part and parcel to "correct" code. There are reasonable cases where using namespace std in non-vendor code is probably appropriate. For example, I know someone who's a perfectly competent C++ programmer, but has difficulty with long identifier sequences because his typing accuracy is hampered by having large hands... --Michael Mol 13:59, 25 May 2011 (UTC)
Just checking. I'll include it in mine, since having std:: everywhere makes it hard for me to read, but I won't go editing existing examples. :) MagiMaster 21:28, 25 May 2011 (UTC)