Boost logo

Boost :

From: Stewart, Robert (stewart_at_[hidden])
Date: 2002-02-11 16:46:41


From: Karl Nelson [mailto:kenelson_at_[hidden]]
>
> I would never attempt to argue that the letter assigned to printf
> make much sense, but then unless we want a very verbose format
> string they can't be less than cryptic.
>
> Does this really add a whole lot of value
> cout << format("%{1:hex,width=10,pad=0} %{2:dec}")(a)(b);
> over
> cout << format("%010x %d")(a)(b);

I would suggest that ":dec" is the default, so your example is slightly
contrived, but I do think there is value in the more verbose format.

> However, no matter what format has been suggested if it has got
> some level of format specifiers you immediately have to have the
> programmer potentially look at a table to see what is supported.

This is certainly true, but meaningful, descriptive terms make recall far
easier. There isn't much of the printf()-style arbitrary,
this-is-the-only-not-too-unreasonable-letter-remaining, format specifier
selection, so checking help is more to learn what's possible than to
determine how to encode the specifier.

> > Given that by no means does everyone "know printf,"
> abandoning print() is
> > not at all unreasonable, even on a whim. (Ok, not just on
> a whim, but I
> > would have absolutely no problem with totally abandoning
> the printf() format
> > specifiers for something less cryptic, equally capable,
> with type safety.
>
> Abandoning printf on a whim is unreasonable. It is a standard and
> thus deviating from it means imposing some new standard. Creating
> standards on a whim is what Microsoft does.

I was joking. Note the "Ok, not just on a whim" part?

> The arguments for using printf are that
> - it is known by a reasonable large group of C/C++ programmers

And it is unknown by a reasonably large group of C/C++ programmers.

> - the format specifier is stardardized by both Unix and C.

And we all know that both of those are noted for clarity of expression.

> - it appears already in C++ in the form std::printf and friends

"goto" is also part of the C++ standard, by reference, but we general eschew
its use.

> - using multiple standards in a translation database is likely
> to lead to errors and difficulties for translators who
> may not be viewing the source code.

If the translators are working on an application that uses printf(), then
they'll be using printf() formatting. If we create a different formatting
scheme that is standardized, then those same translators can find themselves
working on applications using the new standard. It isn't too likely that
the same application will use both, though I suppose there could be some
transition period where that will be the case.

Your arguments don't sufficiently argue against changing the format. They
merely suggest that it isn't as simple as a drop-in replacement. I never
expected it would be, but that doesn't mean that the change is inappropriate
or undesirable. It means that the benefit must be sufficient to overcome
the bother it will cause.

There are flaws in the printf() format specifiers that go beyond the
problems inherent in print() itself. I think it is well worth our time to
try to find a better scheme. James Kanze's point about pushing all the way
toward "print using" and the like is well worth pursuing. This is not to
say that there isn't a place for a type-safe form of printf()-style
formatting. I'm just saying that I'm disinclined to use such a thing, and
would prefer something altogether different.

Rob
Susquehanna International Group, LLP
http://www.sig.com


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