#2330 Dynamic Programming

rasa Sun 17 Aug 2014

I wonder how often Dynamic Programming is being used and what it is used for mostly? Is there something like method_missing in Ruby?

SlimerDude Sun 17 Aug 2014

Dynamic programming in Fantom is more lower level than in other languages. There is no build-in mechanism for adding or removing methods or fields (hence, no, there is no method_missing method), but what it does give you is Obj.trap().

All calls made with the -> operator skips (most of) the compilation checks and at runtime the call is routed to Obj.trap(), or any overridden version there of. The class that implemented Obj.trap() may then do whatever it likes, with what ever arguments that were passed.

I'm not a big fan of dynamic typing but I do use it occasionally in testing when I can't be bothered to write a cast!

Butter uses it a little to condense method calls on a relatively unknown stack of objects.

rasa Sun 17 Aug 2014

OK. Thanks.

tomcl Sun 17 Aug 2014

Fantom allows implicit type narrowing anywhere. That is not dynamic programming, but it does reduce the cruft of type casts that other statically typed languages need.

It is sort of a little bit like dynamic programming because some of the type checking is derogated to the runtime.

SlimerDude Sun 17 Aug 2014

Yeah, the implicit type narrowing is awesome!

Tomcl did a bang up job in finding out and describing all the boundaries for this. (See his tutorial and posts.) I don't think I fully understood, nor appreciated, the power of this until Tom made me understand! :)

Login or Signup to reply.