If you’ve been a programmer sometime in the last fourteen billion years you’ve noticed that there’s this conversation about type systems, specifically about comparing static type systems to dynamic type systems.
Dynamic typing doesn’t mean you can change the type of a thing (even though you sometimes can) it means you can change the shape of types themselves at run time. It means that you can tell a variable to write itself some new, strange, dynamic behavior, but you don’t tell it what to write, you tell it how to decide what to write. And you can eliminate a lot of duplication this way.
But static type systems don’t give you that ability. You have to define the shape and behavior of a type at compile time.
I know what you’re thinking: that really stinks! I want the ability to muck about with my variables, and have them run my code against their own internals and have them write new methods for themselves, and decide how they handle calls against methods that don’t exist, and even crazier things.
The static type system folks can do something that’s really powerful. They can use the type system itself as a global registry.
You see this in a lot of the C# written today, especially the stuff that makes heavy use of an IOC tool and generics. They’ll ask the system to get all the types that implement some interface, or for the types that close some interface and another type. Then they take these types and instantiate one instance of each of them, and use those instances in some way. Each instance runs in a chain or pipeline, or to apply a series of filtering functions to a data set.
The type system becomes a big dispatch table, with type names as global keys, but it’s more like a dispatch tree, because of polymorphism and generic type parameters and all that.
It’s freakin’ cool, once you start doing it – it’s elegant and easy compared to the old stodgy way of programming. And the IOC tools they use keep getting more interesting features that let them query the type-system-as-dispatch-tree in novel ways.
The dynamic type system folks will shrug and suggest implementing dispatch table with a hash like they’ve been doing in Perl for 15 years.
The static type system folks keep losing because their arguments are bad – Compile Time Checking and Tooling just aren’t cutting it. But they may be onto something if they could articulate the benefits of this global registry better than I can.