Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't actually think that DI/IoC are <em>that</em> uncommon in Python. What <em>is</em> uncommon, however, are DI/IoC <em>frameworks/containers</em>.</p> <p>Think about it: what does a DI container do? It allows you to </p> <ol> <li>wire together independent components into a complete application ...</li> <li>... at runtime.</li> </ol> <p>We have names for "wiring together" and "at runtime":</p> <ol> <li>scripting</li> <li>dynamic</li> </ol> <p>So, a DI container is nothing but an interpreter for a dynamic scripting language. Actually, let me rephrase that: a typical Java/.NET DI container is nothing but a crappy interpreter for a really bad dynamic scripting language with butt-ugly, sometimes XML-based, syntax.</p> <p>When you program in Python, why would you want to use an ugly, bad scripting language when you have a beautiful, brilliant scripting language at your disposal? Actually, that's a more general question: when you program in pretty much any language, why would you want to use an ugly, bad scripting language when you have Jython and IronPython at your disposal?</p> <p>So, to recap: the <em>practice</em> of DI/IoC is just as important in Python as it is in Java, for exactly the same reasons. The <em>implementation</em> of DI/IoC however, is built into the language and often so lightweight that it completely vanishes. </p> <p>(Here's a brief aside for an analogy: in assembly, a subroutine call is a pretty major deal - you have to save your local variables and registers to memory, save your return address somewhere, change the instruction pointer to the subroutine you are calling, arrange for it to somehow jump back into your subroutine when it is finished, put the arguments somewhere where the callee can find them, and so on. IOW: in assembly, "subroutine call" is a Design Pattern, and before there were languages like Fortran which had subroutine calls built in, people were building their own "subroutine frameworks". Would you say that subroutine calls are "uncommon" in Python, just because you don't use subroutine frameworks?)</p> <p>BTW: for an example of what it looks like to take DI to its logical conclusion, take a look at <a href="http://GBracha.BlogSpot.Com/" rel="noreferrer">Gilad Bracha</a>'s <a href="http://NewspeakLanguage.Org/" rel="noreferrer">Newspeak Programming Language</a> and his writings on the subject:</p> <ul> <li><a href="http://GBracha.BlogSpot.Com/2007/06/constructors-considered-harmful.html" rel="noreferrer">Constructors Considered Harmful</a></li> <li><a href="http://GBracha.BlogSpot.Com/2007/12/some-months-ago-i-wrote-couple-of-posts.html" rel="noreferrer">Lethal Injection</a></li> <li><a href="http://GBracha.BlogSpot.Com/2009/06/ban-on-imports.html" rel="noreferrer">A Ban on Imports</a> (<a href="http://GBracha.BlogSpot.Com/2009/07/ban-on-imports-continued.html" rel="noreferrer">continued</a>)</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload