dynamic classes and duck typing

retard re at tard.com.invalid
Sun Nov 29 10:27:45 PST 2009


Sun, 29 Nov 2009 14:59:27 -0300, Leandro Lucarella wrote:

> Walter Bright, el 27 de noviembre a las 15:30 me escribiste:
>> One thing Java and Python, Ruby, etc., still hold over D is dynamic
>> classes, i.e. classes that are only known at runtime, not compile time.
>> In D, this:
> 
> I like the feature, but I don't understand where is the duck-typing in
> all this. I think you're confusing duck-typing with dynamic-typing or
> I'm missing something?

Well it seems like the duck typing happens all on compile time with the 
new feature. You get some of the features of true dynamic languages, but 
not all. You can't really write python/ruby style dynamic code with it, 
e.g.

class foo {
  void sayHello() { print("hello"); }
}

auto bar = new foo();

try {
  bar.sayBye();
}
catch(MethodNotFoundException e) {
  ...
}

auto bye_routine(Object o) {
  return o.sayBye();
}

bar.sayBye = { bar.sayHello(); return "and bye"; }

println(bye_routine(bar));

Of course this is inefficient and error prone but that's what's it all 
about in dynamic languages. You get tons of flexibility.



More information about the Digitalmars-d mailing list