From: Mattias Flodin (flodin_at_[hidden])
Date: 2002-04-09 12:31:11
On Tue, Apr 09, 2002 at 10:26:02AM +0100, Paul A. Bristow wrote:
> > Which is more readable?
> > cout << "CPU " << cpu_number << " (mem" << free_mem << "): multiply " <<
> > rows << " X " << cols << " matrix, mode = " << "'" <<
> > transpose_mode <<
> > "'" << endl;
> > versus
> > printf("CPU %d (mem %d): multiply %d X %d matrix, mode = '%c'\n",
> > cpu_number, free_mem, rows, cols, transpose_mode);
> > Personally, I think the latter.
> But that's because it is more familiar ?
> I MUCH prefer the latter (not having learnt C before C++, and never having
> used a printf statement yet!).
Did you mean to say you prefer the former?
I have been using iostreams for 10 years at least, and the printf family for
perhaps three years, so I don't think I'm just subjectively biased toward
printf. I use iostreams due to type safety and extensibility, but for
readability I would favor printf. I believe that if one were to conduct a
survey on people without prior programming exposure, a large majority would
say that the printf syntax is more easily grasped.
But, as others have pointed out in this thread, this is what the format
library aims to solve in a type-safe way (sorry if I'm wandering on the edge
of redundancy with this post).
-- Mattias Flodin <flodin_at_[hidden]> - http://www.cs.umu.se/~flodin/ Room NADV 102 Department of Computing Science Umeå University S-901 87 Umeå, Sweden -- "A good thing about C++ is that only friends can access your private parts"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk