[Lazarus] Does Lazarus support a complete Unicode Component Library?
Jürgen Hestermann
juergen.hestermann at gmx.de
Tue Feb 22 18:23:57 CET 2011
John schrieb:
> Probably because that was the "normal" way of doing it,
> since ansi/long string was added to Dephi a *long* time ago.
Well, an even longer time ago the type "String" was a ShortString of max
255 characters.
My first contact with the "modern" (generic) meaning of "String" caused
me lots of headache
because I was not even aware that the meaning suddenly changed to be
generic.
> Also simply less typing, more readable if I always know that
> a string is just a string.
But that's just the problem: If you don't know (mind) about the
string type incarnation then you blunder into lots of traps.
I always need to know how a certain type is handled and stored.
Otherwise I could not avoid all the special problems that arise.
If I don't know that ShortString is limited to 255 characters and if I
don't
know that AnsiString is a (reference counted) pointer and if I don't
know that assigning two AnsiStrings just copies the pointer (while
for ShortStrings the whole string is copied) and if I don't know
about copy-on-write for AnsiStrings then I get into real
trouble too often.
Trying to avoid all the hassle that comes with different string types
(and encodings) by just using the generic string type is wishful
thinking IMO.
> Sure, if you are doing lots of
> stuff with multiple string types, it makes good sense to be
> specific.
I think this is unavoidable. Sooner or later you cannot avoid
to learn all the string specials.
> If I just want a counter, I will just use "integer").
I always use LongInt because when using integer I am not sure what range of
numbers I will get. Who knows what special command line or compiler
switche changes this to 16 bit or even less. Then my program would
not work anymore. I have to makes sure that my expectations to a
certain data type are correct all the time.
> I suppose if the ansistring type remains, I can do a global
> replace on ALL my code, or redeclare string as ansistring,
> or something, but I don't see why there should not be a
> compiler switch to do it,
I still would prefer the search and replace. Often the code
has to be changed too. A program that was written with ShortStrings
in mind may not work properly with AnsiStrings (just think about
records with Strings).
> What I was really afraid
> of was that Graeme had declared ansistring to be surplus to
> his needs, and that therefore there was no need for it to exist.
I did not unterstand him this way. I think he only wanted to point
out that the *generic* type string should always be as modern as
possible (i.e. AnsiString and if it comes to encoding then UTF8).
Nevertheless, I would try to avoid such generic types at all.
More information about the Lazarus
mailing list