Dynamic vrs. Any


I have been looking around for an exact definition of why these two are different, programming and compiler wise. ? :slight_smile:

1 Like

Exactly, thanks!

For others; seems the real difference from that paper says Any has no dynamic field access.

This means any time(no pun intended) you use Any as a type, you have to explicitly cast to a concrete type before you can use fields of the hidden Any type after casting. eg (Field, Method access)

I think it’s best practice to:

  • try to type anything or leave it up to compiler or (if you have time) use macro’s to help to create the types
  • if that’s not possible, use Any as much as, or use things like haxe.DynamicAccess
  • and use Dynamic as last option because that disables all the goodness the compiler could give.

I think, unless you write a library or access external stuff outside your Haxe code, using things like Any/Dynamic aren’t needed.


I have been writing bindings for JS so sludge is inevitable with that translation.