[fpc-devel] Templates / Generics

Michael Van Canneyt michael at freepascal.org
Mon Nov 7 20:42:13 CET 2005



On Mon, 7 Nov 2005, Anton Tichawa wrote:

> Marc Weustink wrote:
> 
> > Bram Kuijvenhoven wrote:
> > 
> > > Micha Nelissen wrote:
> > > 
> > > > Bram Kuijvenhoven wrote:
> > > > 
> > > > > Florian Klaempfl wrote:
> > > > > 
> > > > > > - we'll use a syntax as close as possible to Chrome, e.g.
> > > > > > type
> > > > > > TList<T> = class
> > > > > >  ...
> > > > > > end;
> > > > > 
> > > > > 
> > > > > 
> > > > > I greatly favor this syntaxis above the generic-modifier. It
> > > > > will look at a lot more familiar to most programmers (due to
> > > > > e.g. C++ and Java), 
> > > > 
> > > > 
> > > > 
> > > > "Must look familiar" programmers should be fired.
> > > 
> > > 
> > > 
> > > Of course, the implementation of generics in Pascal should not depend
> > > solely on how it is implemented in other languages. I should in the
> > > first place fit into Pascal.
> > 
> > 
> > Since it is already decided that it would be <> I didn't mix into the
> > discussion anymore. However, I'll make a comment on this.
> > 
> > > Does <> for generics fit into Pascal? Well, we use [] for array
> > > indexing, and () for parameter passing to
> > > procedures/functions/methods. So why not use <> for passing
> > > parameters to generic types? And, similar to the case of function
> > > calls and array indexing, these <> could follow the type identifier
> > > directly.
> > 
> > 
> > Params are passed to a procedure define like
> > 
> > procedure MyProc(param, param, ..)
> > 
> > Arrays are declared like
> > 
> > A: array[0..9] of ...
> > 
> > And generics.... they are soly defined by the fact that a type has <> in
> > it.
> > 
> > That is imo inconsequent.
> > 
> > Marc
> > 
> I aggree. Why not use new keywords 'template', 'generic', like the current
> 'array' or record'? That would make the code more readable, and remove
> ambiguity problems. It won't cost much, compared to the total size of a
> template.
> 
> It's also more pascal-like, as opposed to C, where e. g. a pointer is denoted
> with '*' and, at the same time, identifies an array etc.
> 
> (sorry if this is out of time or had already been discussed - I just entered
> this thread here).


Personally, I also think that a keyword is in order, just as for 'Operator'.
'Generic' is the obvious choice. Something like

 TMyGenericClass = Generic Class (Ancestor,TemplateName)
 end;

etc. the (,,,) syntax is used for interfaces as well, so that isn't too horrible.


I think < > is an ugly C++ hack, and I would very much regret seeing the beautyful
Object Pascal language butchered by such things.

Michael.



More information about the fpc-devel mailing list