dynamic classes and duck typing

bearophile bearophileHUGS at lycos.com
Wed Dec 2 08:32:14 PST 2009


Walter Bright:
> But with mechanical checking, you can guarantee certain things.

Usually what mechanical checking guarantee is not even vaguely enough, and such guarantee aren't even about the most important parts :-)
Unit tests are more important, because they cover things that matter more.
Better to add much more unit tests to Phobos.


> Where's the advantage of:
>      assert(a is int)
> over:
>      int a;
> ? Especially if I have to follow the discipline and add them in everywhere?

Probably I have missed parts of this discussion, so what I write below can be useless.
But in dynamic code you don't almost never assert that a variable is an int; you assert that 'a' is able to do its work where it's used. So 'a' can often be an int, decimal, a multiprecision long, a GMP multiprecision, or maybe even a float. What you care of it not what a is but if does what it has to, so you care if it quacks :-) That's duck typing.

Bye,
bearophile



More information about the Digitalmars-d mailing list