dynamic classes and duck typing

Leandro Lucarella llucax at gmail.com
Mon Nov 30 17:26:01 PST 2009


Bill Baxter, el 30 de noviembre a las 16:09 me escribiste:
> On Mon, Nov 30, 2009 at 3:38 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> > Walter Bright:
> >> So am I. It seems to be incredibly powerful.
> >
> > Very powerful things can be dangerous too, they can lead to bugs, etc.
> 
> I'm a bit concerned about what this does to introspection.
> With a dynamic language like Python, adding runtime methods does not
> interfere with your ability to enumerate all the methods supported by
> an object.
> With this opDispatch it's no longer possible for the compiler to know
> what list of methods a class responds to.

That's another reason to have a better support for dynamic types, even
when implemented in the library.

Maybe a mixin can be provided to enable some basic functionality, that's
common to all objects using opDispatch(), like enumerating the runtime
members or checking if a member exist.

Anyway, this problem is present in dynamic languages too, for example if
you use the __setattr__(), __getattr__() and __hasattr__() magic methods
in Python, you can't use introspection to see what's in the object, you
have to know its internals to get that information.

There are two levels of dynamicity (at least in Python), you can add
real members to an object (which can be inspected using the standard
Python facilities) or you can use those magic methods (which kills the
introspection too).

The problem with D (using opDispatch()) is you can't add real members, you
can only use magic method to add members at runtime. And that's why
I think it would be nice to have some standard facilities to do this extra
work, otherwise every D programmer will come up with its own
implementation and interoperability will be a nightmare.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Ah, se va en 1981? Pero por qué? ... Ah, porque ya había sido determinado,
entonces quiere decir que pronto vamos a elegir presidente nuevo nosot...
Ah, nosotros no? Ah, lo van a elegir en la ... Ah! Quiere que le diga? Muy
bien pensado, porque cada vez que lo elegimos nosotros no duran nada!
	-- Tato vs. Tato (1980, Gobierno de Videla)



More information about the Digitalmars-d mailing list