[fpc-pascal] Weird string behavior
Santiago A.
svaa at ciberpiula.net
Fri Jul 22 21:49:39 CEST 2016
El 22/07/2016 a las 17:56, Jonas Maebe escribió:
>
> There is no hidden secret knowledge. Everything is documented and the
> information is linked from the release notes. The "principle of least
> surprise" has been applied in the sense that we didn't invent our own
> system that introduces small or large differences compared to how
> Delphi behaves in the same situation (and if there are differences,
> then those are bugs in our implementation).
With hidden knowledge I don't mean it's not documented, I mean that's
like small print in contracts.
Only those who know there is trick with adding are going to check
manual. Complex things and pushing the language to its limits could
require reading manual, adding two strings shouldn't.
MyString := expression
I really shouldn't need to know if right expression uses '+', or the
result of a function, or '*', to guess what MyString type is.
In addition, changing the codepage on the fly if a bad idea.
If I cant change the codepage dynamically (I don't like it, but let's
live with it), let me assign it explicitly, don't change it on the fly.
SetCodePage(MyString,win1252);
MyString := AnsiToUTF8(Ansi1 + Ansi2); // Automatically converted to
Win-1252 before assign
MyString := AnsiToUTF8(Ansi1) + AnsiToUTF8(Ansi2); // Automatically
converted to Win-1252 before assign
SetCodePage(MyString,utf8);
MyString := AnsiToUTF8(Ansi1 + Ansi2); // No conversion needed
MyString := AnsiToUTF8(Ansi2) + AnsiToUTF8(Ansi2); // No conversion needed
MyString := Ansi1 + Ansi2; // Automatically converted to Utf8 before
assign
None changes the codepage of the String but me
I don't like automatic conversion, but let's live with it. But I think
that automatic change of var type is really wrong.
This is Pascal, not bash or PHP.
--
Saludos
Santiago A.
More information about the fpc-pascal
mailing list