dynamic classes and duck typing

Adam D. Ruppe destructionator at gmail.com
Mon Nov 30 16:44:35 PST 2009


On Mon, Nov 30, 2009 at 02:02:46PM -0800, Walter Bright wrote:
> 3. add methods to existing classes (monkey patching) that allow such 
> extensions

I think allowing this in general is a bad idea - the opDispatch should
only be implemented on a small number of classes.

The reason is simple: a typo in a method name should be a compile time error
the vast majority of the time.

If opDispatch was implemented all over the place, allowing random runtime
extensions, the error is put off until runtime.

I'm for having the feature - I just don't think it should be used very often.


To add methods to existing classes at compile time, the way I'd love to
see it done is:

void newMethod(SomeClass myThis...)  myThis.whatever...{ }

SomeClass a;
a.newMethod(); // rewritten as newMethod(a)


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



More information about the Digitalmars-d mailing list