Boost logo

Boost :

From: James Kanze (kanze_at_[hidden])
Date: 2002-01-30 18:11:09


Karl Nelson <kenelson_at_[hidden]> writes:

|> I don't want to reinvent printf though as as has been pointed out
|> dozens of times printf is the standard that outside coding firms are
|> most likely to use. Thus conformation is good.

|> Of course if I had to do it again I would want to make it more clear
|> like.
|> %{ [argument$ type] | [type] [: [flags ... ] }
|>
|> %{x:w30p.>} hex - width 30, pad char ., aligned right
|> %{8.3f:w20} float with 8 char and 3 decimal. width 20.
|> %{} unspecifed argument (next in sequence)
|> %{2} second argument

|> or some such. However, even that can't be nearly as terse as
|> printf.

Terseness isn't always a virtue.

Most of the more complex formatting I've seen has involved laying out
tables. For that, nothing beats the old Basic "print using"; you place
your formatting strings on successive lines in the code, and you see
your alignment without having to count any characters. (When I've
needed to do this with printf, I've generally started by using something
like "print using", and then converted the conversion specifiers to the
printf style. Works for the first go, but doesn't help maintenance
much.)

|> > One thing to keep in mind is that printf does not have to deal
|> > with static manipulators, whereas format does. This means that
|> > format needs more options. For example, a static manipulator may
|> > be set to left align. It would be useful to allow a placeholder
|> > to override this. With printf's current use of '+' and '-', there
|> > is no easy way. However, a syntax like [1:>] makes it pretty
|> > clear that the first argument should be right aligned.

|> You should not have to specify the order of the argument by default.
|> It would induce errors to do so. After all when the programmer
|> writes it they will write. "My dogs name is %s" Reordering is a low
|> level feature not used often excepted in translation.

|> People keep putting to high of emphasis on the reordering which
|> really is only rarely used.

What does "rarely used" mean? I've rarely written a program which
didn't use it.

Your statement was "not used except in translation." But strings that
won't be translated are pretty much the exception today, aren't they?

-- 
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