marc.mutz at kdab.com
Wed Mar 22 11:22:37 CET 2017
On 2017-03-22 10:36, Edward Welbourne wrote:
> On Wednesday 22 March 2017 07:37:27 Thiago Macieira wrote:
>>> Another thing I'd want is for QStringView to carry the pointer to the
>>> QArrayData like QString does.
> Marc Mutz (22 March 2017 09:27)
>> NAK to inheriting from QStringView, publicly or privately. NAK to
>> adding another pointer.
> Is there scope for a common (perhaps private) base, to be used by (at
> least) QString and QStringView, something along the lines of a Java
> interface ?
No. Sharing of functionality is best done with free functions. That
makes the functionality available to the user independent of any
particular class, and allows code sharing by templates, too, across, say
QPoint and QPointF. Or QString and QByteArray. Or QStringView and
QLatin1String and QUtf8String...
> The design of string classes always amuses me: every text-book on
> object-oriented design (that I've seen) launches into it as an example
> and *all* of them give results that I wouldn't want to use in
> code. The problem turns out to be *hard* because we do such a lot with
> strings; and allocation *isn't* a negligible cost. Much of what's hard
> about it is subtle: I've yet to see a string class I thought was Good.
> Good luck in your efforts to break that pattern ;^>
If you mentally remove all the complexity caused by CoW and by not
having QStringView and QUtf8String, then QString comes pretty close. I'd
remove split() and toHtmlEscaped(), replacing them with a
QStringTokenizer and qToHtmlEscaped(), but otherwise, it's the best I've
seen so far.
More information about the Development