[fpc-devel] Modernising Pascal
Jamie McCracken
jamiemcc at blueyonder.co.uk
Sun Feb 20 14:36:35 CET 2005
Hi,
Just wandering if any of you are interested in modernising Pascal which
is looking quite dated when compared to modern languages like Python. I
note free pascal supports a variety of pascal dialects but none of them
are particular modern.
My main gripes with Delphi/pascal is its additional verbosity and
somewhat tedious coding practices which seem superfluous in some cases.
Now I dont mind typing a bit extra to make code cleaner and more legible
but I have a few ideas which would reduce needless typing and improve
clarity at the same time.
(feel free to shoot down any of these ideas)
1. Memory management. Delphi is quite incosistent here by allowing
component classes to be auto managed (via their owner) whilst
non-component class have to be manually managed. The best solution I can
think for this is to reference count non-component classes. This should
be safe for TObjects but obviously not for Tcomponent descendants (cf
circular reference problem) so a protected variable could be added to
TObject to specify whether to ref count it or not (with TComponent
turning it off). This will improve legibility of code too as there will
no longer be a need for having loads of try..finally statements to free
stuff. Backwards compatibility should not be affected so if you call a
free method it will free it whatever its ref count.
2. For Each. Its in Delphi 2005 and every modern language implements it.
3. Increasing the number of base types to include common stuff like
lists (Tlist, TStringList). Python does this nicely and theres no reason
Pascal cant. Base types are dynamically allocated and reference counted
so theres no need to explicitly create or destroy them. The following
code would therefore work :
var strlist : Stringlist;
begin
strlist.add('mystring');
end;
(note I did not use a T in front of StringList so as to distinguish it
from non-base types and also to maintain backwards compatibility with
existing code that uses TStringList conventionally)
jamie.
More information about the fpc-devel
mailing list