What's wrong with D's templates?

Don nospam at nospam.com
Mon Dec 21 00:20:30 PST 2009


Lutger wrote:
> Nick Sabalausky wrote:
> 
>> "Lutger" <lutger.blijdestijn at gmail.com> wrote in message
>> news:hgl440$tlo$1 at digitalmars.com...
>>> Yigal Chripun wrote:
>>>> The .Net implementation isn't perfect of course and has a few issues
>>>> that should be resolved, one of these is the problem with using
>>>> operators. requiring interfaces by itself isn't the problem though. The
>>>> only drawback in this case is verbosity which isn't really a big deal
>>>> for this.
>>> The drawback is not verbosity but lack of structural typing. Suppose some
>>> library has code that can be parametrized by IFoo and I have another
>>> library
>>> with a type that implements IBar, which satisfies IFoo but not explicitly
>>> so. Then what? Unless I have totally misunderstood .NET generics, I have
>>> to
>>> create some proxy object for IBar that implements IFoo just to satisfy
>>> the strong type checking of .NET generics. You could make the argument
>>> that this
>>> 'inconvenience' is a good thing, but I do think it is a bit more of a
>>> drawback than just increased verbosity.
>> It sounds like you're talking about duck typing?
>>
>>
> 
> I'm not sure, I don't think so. From what I understand, duck typing is 
> supposed to be dynamic, while structural and nominative typing are part of a  
> static type system. I meant the non-nominative kind of typing, whatever it 
> is.
> 
> fwiw, this is what wikipedia says:
> 
> "Duck typing is similar to but distinct from structural typing. Structural 
> typing is a static typing system that determines type compatibility and 
> equivalence by a type's structure, whereas duck typing is dynamic and 
> determines type compatibility by only that part of a type's structure that 
> is accessed during run time." 
> 
> http://en.wikipedia.org/wiki/Duck_typing#Structural_type_systems

That Wikipedia page doesn't any make sense to me. Is that *really* what 
duck typing is? If so, it's a complete misnomer. Because it's totally 
different to "if it looks like a duck, quacks like a duck, etc".
If it looks like a duck now, but *didn't* look like a duck three minutes 
ago, you can be pretty sure it's NOT a duck!

Whereas what it calls "structural typing" follows the duck rule 
perfectly. There is no reasoning on that page as to why duck typing is 
restricted to dynamic languages.

There's far too much ideology in that page, it ought to get flagged as 
inappropriate. Eg this line near the top:

"Users of statically typed languages new to dynamically typed languages 
are usually tempted to .."





More information about the Digitalmars-d mailing list