Re: coding style
-Rick- <rick.softly@gmail.com> wrote:
#include <iostream>
using namespace std;
int main(){
cout<<"Hello world"<<endl;
return 0;
}
OR
#include <iostream>
int main(){
std::cout<<"Hello world"<<std::endl;
return 0;
}
I've been told many times that the second option is better coding
practice, but I fail to understand why. I mean, if one had to move to
another namespace in the program, then only then do you have to
change. The first option, imo, makes the code more readable.
What is this forum's opinion?
Without namespaces, library vendors who don't want their identifiers to
conflict with other libraries, have to prepend every identifier they
define with some sort of "wart". One often sees these these warts in C
code for example.
If one refuses to put using declarations and definitions in their code
(as in your second example,) then it is effectively the same as C's
system of having warts prepending every identifier. This is a kind of
hungarian notation.
The namespace feature of C++, along with careful use of using
declarations and definitions, reduces the need for these warts. IMHO,
that is the primary use of the namespace feature, making code cleaner by
reducing the hungarian warts needed throughout the code base.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]