Re: cout vs std::cout
On Sep 29, 8:30 pm, Matthias Buelow <m...@incubus.de> wrote:
Juha Nieminen wrote:
Exactly what do you find "ugly" in the namespace prefixes?
The two ':' symbols? Come on, please.
The entire prefix is visually unappealing (although not really
that much of an eye-catcher in a C++ program) but more
important is the fact that I have to provide more detail than
necessary, which is especially obtrusive in a local context.
What do you mean exactly by "a local context"? One general rule
I've seen is that the length of entity names should be inversely
proportional to their scope: things like i and j are fine for
local, loop control variables, but don't cut it for program wide
globals. Standard out and standard in are program wide globals,
and even std::cout and std::cin are really too short and too
concise for them. (Of course, std::cin and std::cout are bad
examples, since you almost never use them anyway. Consider
std::ostream and std::istream, rather.)
More generally, I can buy the argument that if a given function
is going to use the same entity many times in a small area (and
any given function should be small enough so that its entire
body is a "small area"), then some sort of abbreviation, with
the declaration for the abbreviation at the top of the block, is
acceptable. I can't think of any really good examples involving
IO, but to take Juha's example, if you have a 10 line function
that invokes std::replace in 5 different places, I'd see nothing
objectionable to a:
using std::replace ;
at the top of the function. I'll also use such declarations
when writing unit tests for the class.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34