|
Boost : |
Subject: Re: [boost] request for comments in a new format library
From: Roberto Hinz (robhz786_at_[hidden])
Date: 2018-02-22 23:01:36
âHi Frédéricâ
On Thu, Feb 22, 2018 at 6:46 PM, Frédéric <ufospoke_at_[hidden]> wrote:
> Hi Roberto,
>
> After long time using boost::format, I searched for an efficient
> formatting library and ended using fmtlib which I found extremely
> quick and easy to use. From you benchmark, fmt is almost always the
> quickest solution. I also like very much the fact that I can provide
> some kind of printf format string as this is what is most suitable for
> translations. What would be the advantage to use your library instead?
>
I think the advantages are subtle:
â- you can extend it to write into your own output types
( like if you use some string type other than std::string)
- compile error instead of runtime errors:
fmt throws an exception if there is something wrong in the format string.
Since stringify use a composition of those format functions
<https://robhz786.github.io/stringify/doc/html/format_functions0/format_functions.html>,
you get
compilation errors instead.
- In oder to customize numeric punctuation, fmt forces you to change the
current locate. I find this bad because It means modifying a global state.
Also, I presume that fmt delegate the job to std::ostream in this case,
which I suspect must reduce the performance considerably.
- stringify decouples formatting from translation, for instance:
namespace strf = boost::stringify::v0;
auto str = strf::make_string
[ gettext("your login is: {0}\n your access code is: {1}") ]
&= { strf::right(login, 40) , strf::hex(code) > 40 };
The message to be translated does not contain formatting. Hence:
- There is less chances that the translator team ( which is usually not
composed by programmers ) make some mistake.
- Enables you to change the formatting without requesting the
translators to update the translated strings.
>
> Side question: I am impressed by the very bad timing (x2) of the tests
> on Windows compared to linux. Are they the same kind of
> machines/processors? If yes, why such a difference?
>
âIt's the same machine ( an intel NUC6i5SYH ). I'm impressed too.
âMaybe there is some inaccurateness in my benchmarks that is
dependent on the operating system. But It can't be just that.
Also, in order to copy strings stringify uses internally
std::char_traits::copy.
I think gcc implementations uses some parallelism there, while msvc does
not.
best regargs,
robhz
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk