Ö
Öö Tiib
And you can tell him the issue in one minute.
Geniuses (who solve any problem under minute) can. For them that 'using
namespace std' is certainly harmless. I am not one, sorry. I have never
even met one.
I don't know if a "C++ programmer" who has to sit and stare more than five
minutes to find out a namespace clash can produce many important things in
that time.
Lucky you. Congrats. For me ... world is totally different. I do not claim
to write oh so many important things. C++ code is never simple and short
like in textbooks for me. It takes some time to see what is going on
in it.
Example from my sad practice: some non-std::ref (a member function accepting
same argument) has been assumed by compiler into that std::bind. The error
messages are strange and fail to tell anything about 'ref'. If to qualify that
'ref' then the problems disappear. Also, problems disappear if to rename that member function. That however is not what mine (non-genius) C++ programmer
noob tries. He thinks that he misunderstood something about how std::bind or
std::ref works. Googles and reads. Tries different things. Finally, when he
asks for help frustrated the code is actually wrong too. Then I have to
understand what he wanted to achieve, what he has written and what there
actually should be.
If he had never used 'using namespace std' then he could had written it
himself under 5 minutes yes. So for him and me that 'using namespace std'
is harmful, for you it apparently is not.
But in programming, a string is so universal and has a well defined
meaning, so you better don't use your exotic string unqualified.
Depends. If it is application that works with UTF-8 texts then std::string
is used a lot. If it is a module that has to cooperate tightly with some
MS API or with Java code or with C# code then the texts are more efficient
to handle as UTF-16. As result ... std::string has next to no usage there,
despite being so universal and what else you said.
Use "yourdomain::string" for your exotic string class and just "string" for
std::string. And for the case that you are actually inside yourdomain
namespace, you can still use std::string qualified or if you don't use
std::string at all, just don't #include <string>.
Can't ... if std::wstring is still used. Why ... now we have IMHO so lot of
complications here just to allow that 'using namespace std'?
I don't understand why now you are arguing with such convoluted names like
cord_used_to_tie. I never suggested not using namespaces at all.
That was maybe somewhat silly example on case of string. In general it is
similar to what people often do when they get lot of clashes. Naming thingslike 'electoral_list' or 'mailing_list' instead of 'list' makes sense but
it is easy to go too far there.
Why #including <thread> in the first place?
Any standard library header #included has right to #include on its order
any other standard library headers that the implementation sees fit.
Typically it happens so that maintenance adds #include <something> to some
header. <something> includes <other_thing> that clashes. Maintainer gets
strange error messages (not related to <something>) in somewhat related
code. So there 'using namespace std' was the bear trap that waited for that
maintainer and caused him some nuisance he was not prepared for. Yes,
for the under-a-minute fixers of yours it is maybe non-issue.
The whole point of namespaces actually is, that you don't _have_ to use it
unless you have a name clash. And if you have one, you can fix it on the
client side.
But do not you feel that something has been 'broken' if it needs 'fixing'?
Usually I work in scope of some member function of some class in some
namespace. So there are 3 nested name scopes already. I do not need to
qualify names from these scopes. If the class has base class then names
from it too.
External names I either import or alias or use fully qualified. Such importing
and aliasing code is clear and documents my intentions. Nothing ever clashes.
'using namespace' on the other hand is lazy shortcut that imports whole
namespace, documents nothing and unless it causes clashes immediately it
works like time bomb that one needs to fix in the future.
Otherwise they would not be a real improvement over std_string and your
cord_used_to_tie.
Then they used qualified names...
Yes, indeed, that step I implied. They use that first, to fix clashes.
Still ... they get feed up with fixing clashes and ...
Huh, why that? Are they C programmers?
Because namespaces are broken for coders who use 'using namespace' a lot.
You mean like: yourdomain::yoursubdomain::yoursubdubdomain::list?
No. That is the other edge way how to go too far with namespaces by
by splitting it into small namespaces with long names. C++ has
fortunately a cure to it:
namespace region = thatdomain::thatsubdomain::thatsubdubdomain;