C++ Logo


Advanced search

Re: [std-proposals] String Slicing Draft Proposal

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 19 Mar 2024 09:24:08 -0700
On Tuesday, 19 March 2024 03:47:35 PDT Rhidian De Wit via Std-Proposals wrote:
> > *> * With this proposal, we'll have two/three slightly different ways to
> > do
> > subslicing:> 1a) auto x = str.substr(start, count);> 1b) auto y =
> > std::string(str, start, count);> 2 ) auto z = str.slice(start, end);> Is
> > this subtle API difference going to confuse users? What are going to teach
> > them?*
> I feel like 1a and 2 are meant for similar purposes, but just via a
> slightly different way of achieving it. They both have their use and I feel
> like both are equally valid. In what we should teach newcomers to C++:
> Both. Neither is overly complicated and only offers more choice for those
> who prefer different things.

You didn't address the question of teachability and confusion. I asked the
same thing last week and you didn't address it then either. Offering both has a
cost in teaching, maintenance, and testing. You need to counter that with the
benefit of having the method, and in general that would be in the line of
"allows for something that otherwise would be difficult".

I feel we shouldn't add subtly different methods: please standardise on end
positions, not lengths. Or, at worst, do like <algorithms> and put an _n in
the function name ( la std::fill vs std::fill_n).

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Principal Engineer - Intel DCAI Cloud Engineering

Received on 2024-03-19 16:24:12