Feb 212008

Charlie Calvert writes about dynamic method invocation that has been implemented in the .NET DLR and is working its way into getting proper support by the full VS.NET tool set.  Dynamic method invocation is late binding to the extreme – the lookup is performed at runtime, every time the function call executes.  The compiler has no idea whether the function you’re referring to exists at compile time, so it emits code to make the lookup and call the address with a hope and a prayer.

Hey!  It’s Delphi Variants all over again!  ;>  In Delphi Win32, you can assign an IDispatch COM interface to a Variant, and then make method calls using that variant.  The method calls were reduced by the compiler to a call to GetIDsOfNames, passing the method name in as a string param, and then a call to Invoke, passing the explicit arguments wrapped up in Variants.

Dynamic invoke is certainly a powerful construct for dynamic languages, but it is oft maligned by compiled languages for inherent performance problems and nail-biting ambiguity.  For JavaScript, ambiguity is the source of its seductive dark power.  In the highly structured, explicit, dare I say predictable universe of Delphi syntax, late-binding ambiguity is the entropy engine of insanity.