dynamic classes and duck typing

Adam D. Ruppe destructionator at gmail.com
Tue Dec 1 13:58:32 PST 2009


On Tue, Dec 01, 2009 at 09:17:44PM +0000, retard wrote:
> The lack of type annotations at least removes all typing bugs. 

Quite the contrary, leaving off the type annotation spawns bugs. I had to
write a web app in Ruby last year, and well remember the little things that
slipped past tests, pissing off end users.

"Why can't I access this obscure page?"

Because a != b since for some reason, the database returned a as a string, and
b was assigned by an integer literal.

In D, that would have been an instant compile time error. In Ruby, it was
a runtime error on a page obscure enough that it slipped past testing into
the real world.


You might say that I should have been more disciplined about my testing, or
maybe the company should have hired a dedicated tester, but the fact remains
that it simply wouldn't have happened in D at all. (Even if I left off the
types and used 'auto' everywhere, the compiler would still see the mismatch.)



Until now :P I'm fairly certain that with std.variant and some opDispatch
magic, we can recreate the dynamic system wholesale, so you could, if you
really wanted to, just use var for all types.

The only thing left to make it happen in the language is probably either
opImplicitCast or global assignment operator overloads, and even they aren't
strictly necessary for a lot of programs.


-- 
Adam D. Ruppe
http://arsdnet.net



More information about the Digitalmars-d mailing list