Re: .NET 2.0 to be launched on Nov 8
- From: "Craig Stuntz [TeamB]" <craig_stuntz@xxxxxxxxxxxxx [a.k.a. acm.org]>
- Date: 28 Jun 2005 07:15:11 -0700
Marco van de Voort wrote:
> On 2005-06-23, Craig Stuntz [TeamB] <craig_stuntz@xxxxxxxxxxxxx>
> wrote:
> > Marco van de Voort wrote:
>
> > In .NET all types, including value types can have methods.
> > Including Delphi for .NET,
>
> Hmm, I know there are odditities in .NET in that regard, and I know
> I'm not 100% up to speed on that. Are you sure that actually the
> unboxed types have these methods, and that they are not auto
> converted to be boxed types?
Yes. For full discussion of when value types are boxed in current .NET
releases read Jeffery Richter's Applied .NET Framework Programming.
Nothing is boxed for a simple method call (i.e., without an interface,
reflection, etc.).
> And methods alone is not enough, they
> must be able to be extended with interfaces,
They can. IIRC, in current .NET using such an interface causes the
value type to be boxed, but this is not the case in .NET 2.0. I haven't
read extensively on this topic so do your own research before you
presume I'm correct on this, please.
> and keep being native
> for generics to work. That seems a contradiction to me.
.NET is not Java. Please forget Java's limitations when thinking about
..NET. Generics in .NET don't need interfaces to work, as I've mentioned
to you before.
> > and probably Delphi for Win32 RSN.
>
> I don't see how this could be done.
That's OK since you don't write the Delphi compiler. Suffice it to say
that it's likely to happen.
> > What's more, you can have multiple
> > parameters to your generic type, so if you need specialization for
> > a class you can't extend yourself, like integer, Integer is a class
>
> > you can do that with an additional parameter. This is a bit like the
> > Strategy (GoF) pattern.
>
> Could you give an example for this?
http://www.lambda-computing.com/publications/articles/generics2/
> > But if you like fattening your templates to include operations only
> > allowed for one parameter type, then you'll love this design:
> >
> > http://thedailywtf.com/forums/36558/ShowPost.aspx
> >
> > :P
>
> Actually, despite the unGoFness, that is how most VMs inner loops
> look like :) e.g. you'd probably love
> http://www.stack.nl/~marcov/symbolic.zip :-)
Here's an even better one. After reading this I'm pretty confident
you'll never find the idea of instantiating a template based on a
constant appealing again:
http://thedailywtf.com/forums/37111/ShowPost.aspx
:P
> If you add a constraint, and you derive a type that is not allowed,
> when do you get the error, when the user is running the final program?
No. You get it at the time the code which instantiates the type is
compiled (compiled, not JITted). Note that this is not necessarily the
same time that the generic type itself is compiled, and if the
parameter type is a reference type there will *never* be a
type-specific specialization of the generic type.
> - This leaves the non-ref types, but also ref types that can't be
> enhanced with interfaces without effectively changing type-class.
I can't see why the interfaces are such a big deal here, but maybe
that's just a Java-ism for you? Again, .NET generics just don't need
interfaces at all, and there are other solutions to the specialization
issue -- an entirely separate parameter, as with the link above.
> - I also wonder if you can parameterise a template with an interface.
Um...
1. There are no templates here. I guess you mean generics.
2. Generics accept types as parameters. Interfaces aren't types.
However, you can have a constraint which requires that the parameter
type support a certain interface, and hence the ability to call methods
defined in that interface within the implementation of the generic
type. However, the parameter is still a type, not an interface. Calling
an interface method in this case is no different from doing the same
thing in a non-generic context, i.e. you must implicitly or explicitly
cast the instance as the interface type.
> If so, it would pretty mean that generics are a template subset.
No, but maybe the above makes this clear?
> - For native Delphi this is a disaster, since a lot more types are not
> classes (e.g. strings are not classes
It's hard to tell what you mean here since I'm not clear on whether by
"classes" you mean "types" or "reference types," but as I noted
elsewhere, creating a subclass is not the only way to specialize how
you work with the class in a generic type.
> > This is not true of templates
> > It isn't an implementation detail, either -- even if you're willing
> > to pay the fatness price -- because this fact limits who can use a
> > template.
>
> I don't understand this remark.
I can't specialize a template "defined" in a binary executable. I can
instantiate a generic type with *any* type (including value types) with
nothing more than a compiled (and even NGENed) assembly containing the
implementation of the type.
> >> And it limits generics that operate on unboxed types I think?
> >
> > No, because when a generic is specialized for a value type it
> > really is somewhat like a template. If you limited your comparison
> > of generics and templates to value type parameters you might have a
> > reasonable argument. But this isn't the usual case.
>
> Still, significant enough. For Delphi even more significant, since
> strings are not classes there.
No. Don't presume there is a template-like limitation on such
specializations for value types, because there isn't. The only negative
consequence of the requirement to specialize for value types is
fatness, not a limitation on when the type can be specialized.
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
IB 6 versions prior to 6.0.1.6 are pre-release and may corrupt
your DBs! Open Edition users, get 6.0.1.6 from http://mers.com
.
- References:
- .NET 2.0 to be launched on Nov 8
- From: Paras Kafley
- Re: .NET 2.0 to be launched on Nov 8
- From: Captain Jake
- Re: .NET 2.0 to be launched on Nov 8
- From: Rudy Velthuis [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Rudy Velthuis [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Jeroen Vandezande
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Rudy Velthuis [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Craig Stuntz [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Craig Stuntz [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Craig Stuntz [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Craig Stuntz [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- Re: .NET 2.0 to be launched on Nov 8
- From: Craig Stuntz [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort
- .NET 2.0 to be launched on Nov 8
- Prev by Date: Re: Delphi Community Many Times Stronger Than C++ Community
- Next by Date: Re: Debugging under VMWare
- Previous by thread: Re: .NET 2.0 to be launched on Nov 8
- Next by thread: Re: .NET 2.0 to be launched on Nov 8
- Index(es):
Relevant Pages
|