Dynamic types have the potential to be more than "no static types"
Fragility of the more clever dynamic typing stuff like the &quot;Replacer&quot; is a big problem. An even bigger problem is the increasing difficulty of composing those things together when you want more than one at a time.<p>And that difficulty scales up fast. Consider the Python function decorator. It was quickly discovered that the decorators need to preserve the metadata for the function&#x27;s name, etc., or the decorated functions broke in places that looked at that metadata. But if you have a &quot;function name&quot; parameter that the decorators can modify, now there&#x27;s a mismatch between the fact that the function <i>claims</i> to be &quot;the original GetUser function&quot; but it&#x27;s actually the decorated function. So now you ought to have &quot;the visible function name&quot; and &quot;the real function name&quot;, so for instance, the former works with metaprogramming correctly but the latter allows for correct debugging output on crashes.<p>But what if you decorate a decorator and then want to do metaprogramming on it? Now you&#x27;re got the apparent function name, the real name of the function beneath it, and the real name of the function beneath <i>that</i>.<p>And this is just one dimension of problem. There are many others when you get to metaprogramming like this.<p>The core problem is really this style of metaprogramming, in my opinion. It almost inevitably slips into becoming Deception-Based Programming, in which increasing swathes of the program are trying to figure out what lies to tell to other chunks of the program to get the desired effect. Dynamic typing makes this harder because it makes it very difficult to get a manifest that lists all the behaviors this particular chunk of code or code object has, but even if you were doing this in a static language that didn&#x27;t make that hard, a language would still have a problem exposing all the correct properties and assisting programmers in getting them completely correct.<p>It&#x27;s fun at first, and very powerful at first. But deception-based programming is one of the quintessential ways a code base fails to scale and becomes an incomprehensible tangled mass, code bases that use heuristics to figure out what lies to tell to other bits of the programming to cover up the effects of the lies the other bits of the code are telling. This leads to your programming becoming an embodiment of the phrase &quot;What a tangled web we weave, when first we practice to deceive&quot;.<p>That said, before someone pops up with &quot;but we could do that without deception&quot;... I agree! Or at least, I agree that it should be explored better. I would be interested in a language that somehow enables such metaprogramming, but with a philosophy that says that it will stay &quot;honest&quot; throughout, and basically deliberately eschew and exclude this sort of &quot;transparency&quot;. I don&#x27;t think it&#x27;s necessarily intrinsic to the style. I just think that it&#x27;s <i>sooooo</i> tempting that if you don&#x27;t build a language that excludes it from the get go that the temptation to just shim this little behavior in just here is too tempting, plus the languages tend to end up requiring it, be it accidentally or deliberately, because they afford that behavior and the language ends up being built around how it is at least supposed to be possible. I don&#x27;t know entirely what this would look like.<p>Edit: I say I don&#x27;t know what this would look like, but I have had a couple of ideas. One I&#x27;ve talked about before is to have a clean separation between an &quot;initialization&quot; phase in which metaprogramming is legal, and a &quot;sealing&quot; phase in which it is all done and the metaprogramming becomes invalid&#x2F;illegal. I wrote this for the runtime not to have to be super flexible all the time, but it works for programmers using the system to know that things won&#x27;t change out from under them.<p>The other is some convenient and powerful way to dump things out in their final state post-manipulation. I&#x27;ve gotten some good mileage out of this in my own code that is using a lot of composition. It is very helpful to be able to take the top level of the composed object and say &quot;Tell me what exactly you are made out of&quot;. Even if I&#x27;m not doing metaprogramming based on the response, it&#x27;s a huge debugging help. I see traces and fragments of this idea here and there, but no system that has it coherently integrated in a way I&#x27;d like to see.