Why are IOC containers unnecessary with dynamic languages

后端 未结 9 1441
慢半拍i
慢半拍i 2020-12-04 12:13

Someone on the Herding Code podcast No. 68, http://herdingcode.com/herding-code-68-new-year-shenanigans/, stated that IOC containers had no place with Python or Javascript,

9条回答
  •  既然无缘
    2020-12-04 12:43

    Because they are already built into the language.

    An IoC container provides two things:

    • dynamic binding
    • a dynamic language (usually an incredibly crappy one, built on top of XML or in newer versions on top of Java annotations/.NET attributes)

    Dynamic binding is already part of the dynamic language and the dynamic language is already a dynamic language. Therefore, an IoC container simply doesn't make sense: the language is already an IoC container.

    Another way to look at it: what is it that an IoC container allows you to do? It allows you to take independent components and wire them up together into an application, without any of the components knowing anything about each other. There is a name for wiring independent pieces together into an application: scripting! (That's pretty much the definition of scripting.) Many dynamic languages happen to also be pretty good at scripting, therefore they are perfect as IoC containers.

    Please note that I am not talking about Dependency Injection or Inversion of Control. DI and IoC are just as important in dynamic languages as they are in static languages, for exactly the same reasons. What I am talking about are IoC containers and DI frameworks. Those tools are unnecessary, the design principles aren't.

提交回复
热议问题