Graeme Geldenhuys via fpc-pascal
2021-04-17 19:07:59 UTC
Hi
I'm looking at the wiki and official FPC language documentation. What was
the reason for the decision to make the FPC syntax so verbose regarding
Generics?
eg: What we have now....
type
generic TArray<t> = array of t;
TMyIntegerArray = specialize TArray<integer>;
generic IList<_T> = Interface
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Property Items [AIndex : Integer] : _T Read GetItem Write SetItem;
Property Count : Integer Read GetCount;
end;
generic TList<_T>=class(TObject, specialize IList<_T>)
public type
TCompareFunc = function(const Item1, Item2: _T): Integer;
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
Why couldn't it have been made less verbose like this:
type
TArray<t> = array of t;
TMyIntegerArray = TArray<integer>;
IList<_T> = Interface
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Property Items [AIndex : Integer] : _T Read GetItem Write SetItem;
Property Count : Integer Read GetCount;
end;
TList<_T>=class(TObject, IList<_T>)
public type
TCompareFunc = function(const Item1, Item2: _T): Integer;
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
Out of curiosity I would like to understand the reasoning behind the
verbose usage of the keywords `generic` and `specialize`.
Regards,
Graeme
I'm looking at the wiki and official FPC language documentation. What was
the reason for the decision to make the FPC syntax so verbose regarding
Generics?
eg: What we have now....
type
generic TArray<t> = array of t;
TMyIntegerArray = specialize TArray<integer>;
generic IList<_T> = Interface
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Property Items [AIndex : Integer] : _T Read GetItem Write SetItem;
Property Count : Integer Read GetCount;
end;
generic TList<_T>=class(TObject, specialize IList<_T>)
public type
TCompareFunc = function(const Item1, Item2: _T): Integer;
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
Why couldn't it have been made less verbose like this:
type
TArray<t> = array of t;
TMyIntegerArray = TArray<integer>;
IList<_T> = Interface
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Property Items [AIndex : Integer] : _T Read GetItem Write SetItem;
Property Count : Integer Read GetCount;
end;
TList<_T>=class(TObject, IList<_T>)
public type
TCompareFunc = function(const Item1, Item2: _T): Integer;
Function GetItem(AIndex : Integer) : _T;
Procedure SetItem(AIndex : Integer; AValue : _T);
Function GetCount : Integer;
Public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
Out of curiosity I would like to understand the reasoning behind the
verbose usage of the keywords `generic` and `specialize`.
Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists