Re: Delphi to Visual Studio Conversion Project



Anonymous wrote:

GC I can understand, though I dislike it myself, having seen machines
come to a dead stop while the GC did its thing, then resume again
(this was probably 20 years ago, so I'm sure it's improved greatly).

But other than GC, why choose C# over CBuilder? Is there an
advantage of generics over templates that I'm missing?

Yes: constraints. Templates use some kind of duck typing. I.e., you can
make your type do anythign conceivable (like call methods on it, or
apply operators like ">" and "==") and only at the time of
instantiation (i.e. when you finally assign a specific type to the
generic parameter) you find out that your type, which the template
expects to support "==" or ">" does not support it at all.

Templates are in fact really compiled at the moment they are used. So
the consumer of the template only find out if a type is usable wit the
tmplate when the specific instantiation is being compiled.

Constraints allow you to specify the capabilities of a type (e.g. that
they must implement IComparable, or IPrintable or whatever you can
conceive, and also if the type is a value type or a reference type, if
it must have a (default) constructor, etc.). This means you can perform
what the constraints specify, i.e. you can only cast the type to
IComparable if the constraint says so, etc.

When you compile the generics, all the capabilites are already tested
by the compiler. In C++, you can cast anything to IComparable and only
find out your class doesn't implement it if you start using some of the
methods. IN .NET generics, you find out as soon as you want to specify
the type.

So yes, there are huge differences. .NET generics are precompiled and
compiler checked before use. You can exactly state what your types must
be able to do, if that is required. You don't need the source of
List<T> before you can use it.

C++ templates allow everything at the time of writing, and are in fact
no more than glorified, type checked macros. You (generally) need the
source code.
--
Rudy Velthuis [TeamB] http://www.teamb.com

"They have computers, and they may have other weapons of mass
destruction." -- Janet Reno, Us Attorney General, 02-27-98
.



Relevant Pages

  • Re: The "()" operator revisited.
    ... > the compiler could re-instantiate its body. ... either the constraints have to ... Rather than addressing what you said, let me describe how generics ... formals, when the generic is compiled, when the generic instantiation is ...
    (comp.lang.ada)
  • Re: Cannot apply indexing with [] to an expression of type with ge
    ... I was able to use constraints to make it work ... compiler doesn't seem to be able to figure it out. ... think you can provide a constraint, thus using generics is not a good idea. ... What I can suggest is to create a wrapper class that will handle different ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delphi to Visual Studio Conversion Project
    ... Templates are in fact really compiled at the moment they are used. ... what the constraints specify, i.e. you can only cast the type to ... When you compile the generics, all the capabilites are already tested ... compiler checked before use. ...
    (borland.public.delphi.non-technical)
  • Re: Hashing and comparing of arrays
    ... if the C++ compiler can produce better optimized ... and still verifiable code for the style I will be using (or if I ... You can't really do meta-programming with C# generics -- they are not ... Many of the tricks done with templates in C++ is all about letting the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: .NET 2.0 to be launched on Nov 8
    ... difference in philosophy between generics and templates. ... User-defined specializations make sense in the template world ... anything which meets its constraints. ... Since the compiler can semantically check any ...
    (borland.public.delphi.non-technical)