C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal to add f-strings to C++ as an improvement of string formatting

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 28 Dec 2022 10:11:58 -0500
On Wed, Dec 28, 2022 at 3:17 AM Henry Miller via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Your second objection to format is a basic requirement of all string systems, and so any string library, in any programming language that doesn't feature that is wrong. It is critical that all programmers get used to the idea their strings may need to be translated to some foreign language. Different languages feature different word order and so the order the variables appear in the output must be flexible.
>
> While is seems likely that any string that gets translated will use the strings provided by their UI toolkit and not std, we should still encourage the mindset in young programmers that variables should not be in the same order as the output.

I should point out that this notion also speaks to the intended
durability of programs written in a certain language.

Python code is probably the most prolific user of interpolated
strings. But there's a lot of Python code that is written for
scripting purposes. In these cases, most formatted strings aren't UI
strings that would ever need translating.

But here's the thing. No matter how "script friendly" C++ becomes, I'm
never going to use C++ for a scripting-style task. Python exists, and
is way more trivial to use, so I will use it for those tasks. C++ is
meant for more durable code, stuff that you build and maintain, so the
need for translation increases.

Basically, consider this: in Python, interpolated strings are a
language feature, while formatted strings are a standard library
feature. That says something about the expectations of Python.
Interpolated strings are not inherently bad practice, but they are bad
practices within certain contexts.

Contexts that C++ widely gets used in.

So however nifty they are, they also push C++ programmers to think of
their code as ephemeral. Which it almost never is.

Received on 2022-12-28 15:12:09