Jürgen Hestermann schrieb:

And I think shortstring should generally be discouraged. The standard is
always "255 is enough", but sooner or later somebody hits it:

That's like saying that short integer types like byte or word should be discouraged and only Int64 should be used.

That's a different situation - extending a byte to an wider type is not a problem, done in the CPU every other tick.

Shortstrings are just a completely different string type than ansistrings.

That's it. Every string type must be handled differently by the RTL.

Therefore it is dangerous to use the generic string type because in general a programer needs to know how the strings are stored, otherwise significant bugs are likely.

NACK.

String handling procedures hide the details from the user, and they (have to) do their job well.

If you want to deal with the text (characters) in an string, you have to know much more about the string *encoding*. MBCS strings (UTF...) discourage at all the use of Char, and the use of indexed access to the characters in an string, regardless of the string *type*.


With Shortsstrings you don't have to think about reference counters and other traps that can be cause hard to find errors (i.e. when using ansistrings within a highly nested data structure). Just think of a array of strings. If shortsstrings are used, all data is in one block of memory. You can move it around and make copies of it. But with ansistring this is not so easy. You only have an array of pointers. If you use move() on such an array then the reference counters are not affected and you get into trouble.

Dealing with strings at such an low level should not be required in everydays code. Leave it to the experts to implement TStrings, and work with the higher level methods. Your considerations apply as well to static and dynamic arrays of any type.


If binary data shall be kept in an string, then of course it's wise to use an specific type for such strings, which does no translations of the content. But then the contents should never be moved into other strings, but instead into variables of other types. The type should be something like ByteString or ByteArray, and that type should be incompatible with all other character strings.

DoDi


--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to