ShortString have a big advantage: they can be allocated on the stack. So they are perfect for small ASCII text, e.g. numbers to text conversion, or when logging information in plain English. Using str() over a shortstring is for instance faster than using IntToString() and a temporary string (or AnsiString) on a multi-thread program, because the heap is not involved.
Of course, we could use a static array of AnsiChar, but ShortString have an advantage because they have their length encoded so they are safer and faster than #0 terminated strings.
So on mobile platform, we could end up by creating a new record type, re-inventing the wheel whereas the ShortString type is in fact still supported and generated by the compiler, and even used by the RTL at its lowest system level.
Why? Because some people at Embarcadero thought it was confusing, and that the language should be "cleaned up" - I translate by "more C# / Java like", with a single string type.
This was the very same reason they did hide RawByteString and AnsiString... More a marketing strategy than a technical decision IMHO.
I prefer the FPC more "conservative" way of preserving backward compatibility. It is worth noting that the FPC compiler source code itself uses a lot of shortstring internally, so it would never be deprecated on FPC for sure. 😉
Edited September 22, 2021 by Arnaud Bouchez
节选二
Dalija Prasnikar 971 Posted September 23, 2021
I don't remember anyone complaining :classic_biggrin:
The though process was a bit different. Mobile compilers were supposed to attract new generation of developers. To do that it needed to have some competing features. One was automatic memory management (hence ARC), another one was streamlining string and array indexing - hence zero-based strings. Short strings store length at index zero, so they were completely incompatible with that goal. AnsiStrings with ANSI encoding are not something that exists on mobile platforms, so they were deemed as unnecessary, too. So 8-bit strings were removed.
Unfortunately, what they didn't take into account is impact on existing codebases. The same ones that were supposed to run on all other platforms (yes, you couldn't reuse GUI), but there is not reason to throw away non-GUI code.
Zero based strings wreak havoc in string handling, causing subtle bugs all over the place. Most people after they learned about it would just turn the damn thing off. Removing all other 8-bit strings was also a mistake, because 8-bit strings make a whole a lot of sense in cross-platform, especially on Linux where UTF-8 encoding rules. So while throwing out AnsiString as such made sense, the rest did not. This is also why 8-bit strings were reintroduced, even before ARC was removed - which happened for completely different and unrelated reasons.
And the last, but not the least. TBytes are completely different beast from strings. It is not that just that handling functions were missing. TBytes don't have COW, and also debugger support is extremely limited and you cannot easily inspect textual data stored within.
And we all know how many new customers they attracted to Delphi because it was suddenly cross-platform.
I think the big problem, in Object Pascal in particular, is the amount of subtypes for a particular type: strings!
Like many other factors in the computer, I think it started with the goddamn inheritance of MSWindows, and by consequence the language that created it: "C"
And, over time, the OP was adapted to calm the animalistic principles of skeptical programmers and their criteria of "evolution".
Thus, with the appearance of new platforms, it became clear that the technological "mess" would, one day, show true chaos.
This is clear in many other scenarios, for example, today we have in Fireibird new types for numerical values, because, due to the exponential growth of values, it was necessary to make use of subterfuges to represent such large values....
But don't be sad, because the sadness could be even greater as 128bit computing or higher arrives....
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3