Modules, Dependency Injection, and Newspeak
I'm about to put the finishing touches on the Heron design for its big 1.0 release, by putting in the module system. I left this for last thinking that it would be trivial. Boy was I wrong!
I was going to slap a module system on Heron that looked like Python and be done with it (see this StackOverflow question I asked ). However, through sheer luck I read this blog post by Gilad Bracha and he convinced me I was about to make a big mistake. The problem was, and in part still is, I didn't exactly understand what alternatives I had!
Gilad Bracha's new language is called Newspeak and is heavily inspired by Smalltalk. It is hard for me to follow everything that he proposes because I don't really speak Smalltalk, but he does make an effort to dumb things down a bit in the Newspeak language specification .
The blog post at first sounded like hand-waving to me, but Gilad Bracha is someone worth listening to when it comes to language design. To add to this his ideas receive support from someone else I respect, Phil Wadler.
Philip makes the connection between the Newspeak module system and dependency injection. In addition some people on the Lambda-the-Ultimate.org blog have helped me understand this point further here.
The lesson I have learned so far is that a poorly implemented module system has many downsides, and that it is possible to have a module system which makes it easier to refactor, mock, and enforce security, via explicit dependency injection.
Some useful links I have been using for digging into the subject further:
- Gilad Bracha: Cutting out Static LtU discussion on this blog post
- I Seek a Reasonable Survey on the Concept of "Module System" - LtU discussion
- A modular module system [PDF], by Xavier Leroy
- Newspeak specification [PDF]
- A Ban on Imports and A Ban on Imports (continued)
- PLT Scheme Units (Components)
- Import is not Inheritance - Why We Need Both: Modules and Classes (1992) - by Clemens A. Szyperski

