[fpc-devel] Generics

Danny Milosavljevic danny.milo at gmx.net
Wed Apr 12 09:26:17 CEST 2006


Hi,

Am Dienstag, den 11.04.2006, 18:56 -0300 schrieb Flávio Etrusco:
> On 4/11/06, Danny Milosavljevic <danny.milo at gmx.net> wrote:
> > Hi,
> >
> > Am Montag, den 10.04.2006, 23:33 -0300 schrieb Flávio Etrusco:
> > > On 4/10/06, Danny Milosavljevic <danny.milo at gmx.net> wrote:
> > > > Hi,
> > > >
> > > (...)
> > > > > but thing is I can't see much use for generics for low level
> > > > > tasks.
> > > >
> > > > You need them for any kind of compile-time-type-checked collections...
> > > > so as long as you only do I/O port programming, you are safe... no wait,
> > > > only until you try to store the conversation in a list :)
> > >
> > > You got me confused here.
> >
> > bla: TList(Integer);
> >
> > repeat
> >   i := inp(49330);
> >   bla.Add(i);
> > until i = 0;
> >
> > I meant that no matter what you do, once you need any more than a static
> > number of values remembered, you already need them... (strings are a
> > special case though)
> 
> Do you honestly have any use for generics supporting primitive types
> other than writing half a dozen containers?

Probably not, because my main use is containers. I cringe when I have
TStringList but no TIntegerList, for example... (and all the others)

> 
> > How low is "low level"?
> >
> > >
> > > > > There are relatively few native types that is usually ok duplicate the
> > > > > whole code if it need be.
> >
> > Single
> > Double
> > Integer
> > Shortint
> > Longint
> > Cardinal
> > Byte
> > Char
> > WideChar
> > ansistring
> > widestring
> > set  (all possible set definitions)
> > enum (all possible enum definitions)
> > record (all possible record definitions)
> > array (all possible array definitions)
> > ...
> >
> > and one is supposed to repeat (at least) all collection object classes
> > for each of them? You can't be serious...
> 
> You can't be serious. Why do you need containers or whatever code so
> specific and optimized for all these types? 

In order for it not to be slow :)

> And do you wanna count
> many TObject descendants vs. native types (including records) does the
> e.g. FCL include?

There are many... 
but not all of them will have a specialization automatically from the
start, only on "use".

> 
> 
> > > > are strings classes or primitive in your mind?
> > >
> > > My mind is FPC, so it's a primitive type.
> >
> > I see. TDictionary(string, TObject) doesn't work then? (one of the most
> > used mappings with cgis, at least)
> 
> Why do the String in this case need to be anything other than a String?

I don't understand... string is a primitive type, so it wouldn't work in
this example, no?

> 
> > > > > and about the difficulty of debugging
> > > > > templates (not to say that I prefer name/symbol resolution only
> > > > > through inheritance instead of pre-compiler/macro so much better)...
> > > >
> > > > Depends on if it's done right :)
> > >
> > > Arguably. But considering C++ has almost 15 years of head start and
> > > they couldn't get it right yet, I guess it's not an easy task...
> >
> > They are working pretty well now (in gcc)...
> 
> I'm talking about debbuging, so besides gcc, gdb and some other user
> interface must be working pretty well too; what are they?
> I know that VisualStudio 2003 certainly isn't (I didn't try VS 2005
> yet, but I doubt it is any better is this respect...).

Good question...

> 
> > > PS. BTW I've just realized that not possible to fully replace 'type
> > > erasure generics' in the compiler with 'templates'... at least not as
> > > efficiently, right?
> >
> > A mixture is best: use the same generic specialization where possible
> > and new specializations otherwise...
> 
> If this was the case of course I would have be glad :-) I'd still be
> afraid to have FCL becoming anything like the STL (i.e. as horrible
> and impossible to read as it), though...
> 
> Following the URL Micha sent in a previous reply, I've just read that
> .net 2 supports generics for native type by recompiling the templates
> only in this case. Interesting...
> http://cakoose.com/wiki/microsoft_clr


yeah, nice :)

cheers,
  Danny





More information about the fpc-devel mailing list