[fpc-pascal] String types in a wider perspective (was: private integer is an illegal counter variable)

Juha Manninen juha.manninen at phnet.fi
Tue Dec 1 13:03:37 CET 2009

On lauantai, 28. marraskuuta 2009 12:12:19 J├╝rgen Hestermann wrote:
> > And there are many reasons why there are so many string types nowadays.
> True.
> > Simply use {mode objfpc}{$h+} like lazarus suggests.
> I think the root cause of all these problems are generic types. They cause
>  more trouble than they avoid. I would suggest that noone never uses such
>  generic types but uses shortstring or ansistring (or...) as they need.
>  Telling people to simply use this or that compiler switch is not the
>  solution (you have to explain this over and over again). Generic types
>  should be the exception and not the norm. It begs for trouble in many
>  situations. Using strict types also lets the user read more about the
>  nature of these types and therefore knows more about possible side
>  effects. Someone who has shortstings in mind when using strings would
>  surely use it in a different way as someone who has ansistrings in mind
>  (provided he knows how they are handled by the compiler). And telling
>  people clearly about the implementation of these different types is much
>  better than obscuring them by generic types.

A generic "string" type makes a lot sense when switching between dynamic 
string types (AnsiString, UnicodeString...).
Delphi managed to do the switch almost transparently because they had designed 
their libraries well. Old code using AnsiString just worked after compiling it 
for UnicodeString.
The historical ShortString is handled very differently (explicit memory 
management etc.). It is a different type semantically and so it should be 
different also syntactically.

This apparently small syntax detail has a wider symbolic message. When people 
here are seriously arguing about how important ShortString is ('cause you can 
save 3 bytes or something...) the message for potential new Pascal programmers 
is like:
"If you think ShortString as a default string type is important because it was 
invented at 1970 then welcome to our Old Farts' Freak Club. Otherwise please 
use some contemporary language."
I am almost an old fart by age but still I am looking for new innovations.
Whole computing is still very young and is advancing rapidly. Development 
tools must advance, too.
Now Object Pascal has a place in this ecosystem as a compiled language with 
clear syntax. Virtual machines are still memory hogs and C++ is ugly.
After 50 years nobody cares if virtual machines hog memory because computers 
will have so much resources but not yet so.

I am happy this language is evolving. Generics syntax is a good thing.
Virtual machines or garbage collections would not belong here but I guess they 
are not even planned.

Juha Manninen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20091201/f94cd98f/attachment.html>

More information about the fpc-pascal mailing list