Boost logo

Boost :

From: James Kanze (kanze_at_[hidden])
Date: 2002-02-09 10:28:01


Mickaël Pointier <mpointie_at_[hidden]> writes:

    [I hope I've got the attributions right. The formatting was pretty
    messed up when I got it. ...]

|> >> (the only two arguments I've ever heard against this was that
|> >> "printf" was more intuitive, which is true only for old C coders,
|> >> and that the manipulator approach was very verbose, but I could
|> >> care less about that).

|> > I'll second this!

|> > I am not an old-school C coder, never had to learn printf and
|> > rigoroulsy avoid having anything to do with it. My brief dealings
|> > found it far from intuitive and visually dense so I couldn't see
|> > the wood for the trees.

|> > I'm also against *unnecessary* verbosity, and some of the iostream
|> > stuff may be too far the other way but at least it is clear. When
|> > it comes to trade-offs, I'll take clarity over terseness!

|> > As someone who is observing the thread, rather than participating,
|> > my observation is that I quite liked the [] syntax, and I would
|> > likely investigate any library based on that just for the
|> > 'rightness' of the feel. I will avoid any library based on
|> > printf-style syntax. I'm not yet sure if this library is
|> > targetted at me to begin with though, so take these last comments
|> > with a pinch of salt!

|> Well, all oppinions are in the nature. Mine is opposite to yours.

|> Personaly I appreciate the printf syntax because all the formating
|> stuff is visualy located around the thing you want to format, and it
|> has no consequence on the remaining of the things to be formated. I
|> really hate the c++ stream way of setting precision, width, whatever
|> else, because it's more a kind of state machine that keep settings
|> until they are changed.

There are, I think, two separate aspects. The stickyness of the C++
formatting is a real pain in many ways. Worse is the fact that the
non-stickiness of width is the responsibility of each individual
formatter; someone always forgets, and since most of the time, the
following formatting sets the width, the error goes unnoticed.

The grouping issue is more open. In printf, the formatting information
is grouped where the text will occur in the output. In ostream, if
manipulators are used, it is grouped near the parameter (which is also
near where the text will occur in the output). There are reasonable
arguements for both, I think.

Globally, the ostream formatting becomes a pain when you need to use
three or four different manipulators, and reset the values after use.
(There's nothing worse than a function which leaves the base set to
hex.) When doing formatted output directly with ostream, I use a set of
my own manipulators, which regroup several standard manipulations
(setting fixed, width and precision at once, for example), and restoring
the state at the end of the full expression.

-- 
James Kanze                                mailto:kanze_at_[hidden]
Conseils en informatique orientée objet/
                    Beratung in objektorientierter Datenverarbeitung
Ziegelhüttenweg 17a, 60598 Frankfurt, Germany Tel. +49(0)179 2607481

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk