Poll on improved format strings.

renoX renosky at free.fr
Tue Mar 6 06:53:48 PST 2007


Hello,

I've made a templated format string templates joined in attachment (this new version is improved thanks to Frits van Bommel), but I'm not sure about the syntax of the format string.

The idea is: printf format string are interesting because they are powerful but they suck because the %d,%s, etc are in one part of the function and the corresponding variable are in a different part of the function (Tango has the same problem), writef improve this by allowing "... %d",var," ... %s",var2 but it's still not ideal because in the gluing of the various strings, it's easy to forget a space or a comma thus providing a not very good output.

So my idea would be to have embedded expression like this "... %08d{var1+var2} ...", but it's not easy to provide a good syntax/semantic, so I'd like some remarks:

-Should the mix of printf format and new style format string be allowed? (It is in the current implementation).
This has the advantage of nearly keeping  the compatibility, the problem is with the format string "..%d{..." in printf this means a number followed by '{' but with the new format this creates an error.
It is possible to escape the '{' to allow this, ie to say that '%{' is '{' so now '%d{' would need to be '%d%{', this has the inconvenient that it's not possible to have the embedding format '%{var}' which would be the shortest syntax..
Another possibility would be to say that if you want to have '... %d{ ...' one need to write it has '.... %d',var,'{ ....', this would permit to have the '..%{var}...' embedding syntax.

-What to do with non-const char[]?
They cannot be parsed by the template, so one possibility is to allow only const char[] parameter or to allow non-const char[] and leave them alone (they may contain printf-style format string). This is what the current implementation is doing but I'm not sure if the added flexibility is not confusing: const char[] can contain both printf-like format and 'new embedded format' but non const char[] can only contain printf-like format string.

- Another possibility would be to use a different character '#' (like in Ruby) for these new format string..

I'd like some inputs to see if there is a majority in favour of one style or the other..

renoX

-------------- next part --------------
A non-text attachment was scrubbed...
Name: putf.d
Type: application/octet-stream
Size: 9378 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20070306/ab5b70d2/attachment.obj>


More information about the Digitalmars-d mailing list