Boost logo

Boost :

Subject: Re: [boost] [general] What will stringhandling inC++ looklike inthe future [was Always treat ... ]
From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2011-01-19 23:29:01


On Thu, Jan 20, 2011 at 12:13 PM, Dave Abrahams <dave_at_[hidden]> wrote:
>
> I would prefer to be handling something that presents the abstraction
> "character string."  I'm not sure exactly what that looks like, but
> I'm pretty sure the "individually addressable and mutable chars" part
> should go.  I'd like to see an interface that prevents corrupting the
> underlying data such that it no longer represents a valid sequence of
> characters (or at least makes it highly unlikely that such corruption
> could happen accidentally).  Furthermore, there are lots of string-y
> things I'd want to do that aren't provided—or aren't provided well—by
> std::string, e.g. if (s1.starts_with(s2)) {...}
>
> Does this make more sense?
>

This discussion is interesting for a lot of reasons. However, I think
it's time to address the root cause of the problem with strings in
C++: that the way we think of strings right now is broken. Everything
follows from this basic problem.

It's time to call a spade a spade: std::string is not as well thought
out as everybody might seem to think. I think since we've had
something like 20 years to think about this problem, it's time to
consider revolution instead of evolution.

Immutable strings with lazy operations seem to be the most effective
way to deal with strings from a design/implementation perspective.
Encoding is just a matter of rendering, or in fusion/mpl parlance is a
view of the data.

String mutation is a concurrency hindrance, encourages bad programming
practice, and is generally an overrated feature that makes designing
efficient strings still revert to pointers and value twiddling. In
this day and age with all the idioms in C++ we already know, we should
really be thinking about changing the way people think about strings.

Of course it shouldn't be as drastic as wiping out std::string from
the face of all programs -- but something that allows for taking data
from an std::string and becoming immutable, allowing lazy operations
on it, and overall making a crazy efficient string implementation
should be the goal first before we think about dealing with encodings
and what not. Maybe it's time someone formalizes a string calculus and
implements a string type that's worthy of being called a modern
string.

Going-back-to-just-watching'ly yours,

-- 
Dean Michael Berris
about.me/deanberris

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk