Boost logo

Boost :

From: Brey, Edward D (EdwardDBrey_at_[hidden])
Date: 2002-01-31 10:35:02

> From: bill_kempf [mailto:williamkempf_at_[hidden]]
> >
> > It's a matter of engineering principle: locality of reference, as
> applied to
> > its impact on the programmer. With the printf-style, you get good
> locality
> > of the format text:
> >
> > "Task [1] will complete within [2] second(s)."
> This is *NOT* printf-style formatting. This is solely syntax for
> positional parameters, which I very strongly support. (And I could
> care less if the delimiter string syntax is %1%, %1$, [1], (1), %001
> or any other variant you want to throw at it.)

I think we have a difference in connotation of "printf-style" formatting. I
was using the term broadly, simply to mean "the use of placeholders". I
wasn't trying to imply the existence of position indicators. They were just
an artifact of my example. The difference I'm considering is whether you
have one string with placeholders or many strings separated by their
variables and connecting operators.

> > Each type of locality has its own advantage. There is a tradeoff,
> and which
> > style is best depends on the situation. In my experience, I've
> found that
> > when dealing with full English sentences, the locality of the
> format context
> > is most desirable, whereas for short, simple outputs, like those in
> some
> > trace logs, locality of a variable to its text is most desirable.
> When speaking of locality, to me the important thing is to keep the
> formatting code with the object being formatted. In other words, I
> think that:
> cout << format("[1]") << width(10) << foo;
> is much preferrable to:
> cout << format("[1:10]") << foo;
> I think it's easier to read and comprehend, and it certainly will
> make the translation of the format string easier.

I don't think that it is comprehensive to say "the important thing". The
proximity of formatting directives to the object being formatting can be
important. Sometimes it is the most important. But not always. Sometimes
the proximity of the formatting directive to the surrounding text in the
format string is more important. Indeed, there are times when laying out a
table that it makes no difference at all what object lives there (its type
may not even be known until run-time), but the amount of space reserved for
the display of that object is fixed at design time.

Boost list run by bdawes at, gregod at, cpdaniel at, john at