Re: .NET 2.0 to be launched on Nov 8
- From: Marco van de Voort <marcov@xxxxxxxx>
- Date: 28 Jun 2005 05:24:00 -0700
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? And methods
alone is not enough, they must be able to be extended with interfaces, and keep being
native for generics to work. That seems a contradiction to me.
> and probably Delphi for Win32 RSN.
I don't see how this could be done. In a compiled language, such tricks are expensive,
see e.g. the horrible performance of variants.
> 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? (since there was also a kind of
specialization not allowed on generics, but IIRC that was for the primary
type, so that doesn't have to conflict.
> 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 :-)
I still prefer the attitude of my old programming teacher. If you can make a
decent case for it, then it is a good practice. All those general best
practices are general recommendations, not mandatory directives passed from
half-gods. Such examples are meaningless without proper context and
argumentation of the original programmer.
>> > difference in philosophy between generics and templates. Templates
>> > are intended to be fat, and intended to be entirely specialized at
>> > compile time.
>>
>> I don't know what you mean by this remark. Of course they are
>> specialised at compiletime. But so are generics, since those
>> interface constraitns have to be compiler check too.
>
> No. This is totally different, because it isn't the same compile,
> necessarily. If you're confused by this you should probably read the
> articles again. ISTM you are confusing yourself by presuming that what
> happens in the JITter with a generic is similar to what C++ compilers
> do when they compile a template, but this is *not* true.
You are confusing the semantical check with the actual instantiation of code.
Or at least that is what I was (and still am) thinking.
Maybe I can ask you a question to make this more clear:
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?
>> > User-defined specializations make sense in the template world
>> > because there is no possibility that someone will try to use your
>> > template with a class which is unknown at the time the template is
>> > compiled/specialized.
>>
>> This is incorrect. You are confusing the term compilation here. Read
>> your own links, the final specialisation for .NET also happens in the
>> JIT. So generics are not that different at all.
>
> I read the articles, and, more importantly, I understood them. Here is
> one sentence you need to read over and over again until it pushes the
> template presumptions out of your head:
>
> "When the runtime specializes a generic, it creates one specialization
> for all ref classes."
I under stand, the basic principle of that division is clear, the base
principle btw being pretty much only that. (avoiding code generation per
instance at the cost of decreased flexibility and implementation problems
for native languages)
a few remarks though
- This leaves the non-ref types, but also ref types that can't be enhanced
with interfaces without effectively changing type-class.
- I also wonder if you can parameterise a template with an interface. If so,
it would pretty mean that generics are a template subset.
- For native Delphi this is a disaster, since a lot more types are not
classes (e.g. strings are not classes, calling interface method is more
expensive than normal method )
- I still don't see the big problem with the multiple cg, and the need for
all this.
> 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.
>> 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.
> And since generics specialize like templates with value types there is no
> such limitation.
Which enforces my feeling that .NET generics are pretty much templates<T:aninterface>
with a shorter/clearer syntax. However that realisation makes the picture a bit clearer.
>> But yes, I've seen that in those links. However I don't see the
>> reason for these stupid limitations.
>
> I'm honestly not trying to sell you on anything. I'm just describing
> the way things are.
And that's clear now, though I still don't see any advantages except the
avoiding of multiple instantiation, and why they would do it.
However the template<T:aninterface> <-> generics analogy makes that clearer.
It seems just a subset of templates they want to promote.
.
- Follow-Ups:
- Re: .NET 2.0 to be launched on Nov 8
- From: Craig Stuntz [TeamB]
- Re: .NET 2.0 to be launched on Nov 8
- References:
- .NET 2.0 to be launched on Nov 8
- From: Paras Kafley
- Re: .NET 2.0 to be launched on Nov 8
- From: Tom Reiertsen
- Re: .NET 2.0 to be launched on Nov 8
- From: Jeroen Vandezande
- 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]
- .NET 2.0 to be launched on Nov 8
- Prev by Date: GPL dll with LGPL headers
- Next by Date: Re: Moderation
- 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
|