Everything is dynamically typed

I’ve just seen David Weinberger’s recent Authors@Google talk, a deeply interesting overview of his new book, Everything is Miscellaneous. At first sight, Weinberger’s talk has little to do with programming. He discusses our efforts to classify objects in the world, starting with Aristotelian categories, where there was one and only place for every thing (and, presumably, one thing for every place)–a line of thought rooted on our direct experience with physical objects, culminated with Dewey’s decimal classification system. A line of thought that our modern, digital world has made obsolete. Weinberger is an excellent communicator and makes his points with a fine sense of humour, so, if you have fifty minutes to spare, you can do far worse than pressing the play button below before go on reading why am i mentioning this video in programming musings:

Still with me? Well, the fact is that hearing Weinberger’s thoughts i’ve been remembered of a little exercise i was doing this morning, as part of my recent efforts to finally come to grips with Haskell. You know what? Static typing feels a lot like Aristotelian categorisation: one and only one type for each variable. As is the case with Aristotelian categorisation, there are many situations where a rigid type system works well: we use categories all the time, and they obviously capture part of the structure of the world out there. But they inevitably break down at some point. In my little Haskell exercise (an interpreter for propositional logic), there was a point where it would have been extremely convenient to have more than one type for some of the variables i were using. Maybe it’s just than i’m used to working that way in dynamically typed languages, where the types of the parameters of my functions are in constant flow, and i cherish the ability to widen their domain on the fly.

As mentioned in the talk, Aristotle would be horrified at the prospect of having anything in more than one place of the tree: that would be chaos!. But in our digital world, tagging and mash-ups are arguably revealing themselves as more apt ways to organise our knowledge of the world. There are myriad faces to everything, and allowing different points of view is not only natural, but seemingly useful.

In the same (or, at least, analogous) way, static typing abhors (actually prohibits) variables with mutating types. One has union or algebraic types, that’s true, but one has also the feeling that using too heterogeneous types to construct them is going a bit afield. Could that be as misguided as Aristotelian categories? I don’t know. Building software is so complex that maybe we need the safety net of rigid categorisations. But i’ve noticed repeatedly while programming in, say, Lisp, that using dynamic typing makes things easier in many contexts. The nagging feeling of insecurity i had when i started using Scheme about the lack of type declarations has progressively disappeared, up to the point that languages as beautiful as Haskell can sometimes feel like a straitjacket.

I might be misguided, and perhaps my sense of security is bogus because it derives from very small projects (i have never participated in a large project using a dynamic language), and that liberally bending the type system really leads to chaos in the long run. Maybe the right way to realise this many-facets approach to modeling the world is to put type classes and parametric polymorphism to good use–although even there, i find CLOS generics more natural. But one wonders, could it be that, like our data, the real world problems out there are too complex, too multifarious to fit in a static ontology?

Come to think of it, i’m realising than i’m just badly restating the line of thought people like Alan Kay or Gerry Sussman have been defending for years. Specially their seeking inspiration in biological systems (those complex, messy things so marvelously organised) to model our computing and programming systems. I think that what i’m trying to express (and much, much more) is finely put, for instance, by Alan Kay in his famous talk The Computer Revolution hasn’t happen yet (if you haven’t seen it, please click that play button below) or, more recently by Sussman and Hanson in their paper Building Robust Systems. As i mentioned, in both cases, convincing parallelisms with biological systems are put on the table, and a dynamic outlook to programming systems (including generic functions and MOPs) are favoured. My gut feeling is that these ideas are to programming what Weinberger’s are to data management. I hope that reading and hearing Weinberger, Kay, Sussman and Hanson will convey this feeling better than these somewhat iffy ramblings.

All that said, i still get a kick out of learning Haskell. It must be the Aristotelian in me! :-)

Update: Some interesting comments over at reddit.com point out how my analogies could be (and probably are) flawed. In particular, there’s a reference to what looks like a very entertaining book: Practical Foundations of Programming Languages (PDF), which argues exactly the opposite:

This is a working draft of a book on the foundations of programming languages. The central organizing principle of the book is that programming language features may be seen as manifestations of an underlying type structure that governs its syntax and semantics. The emphasis, therefore, is on the concept of type, which codifies and organizes the computational universe in much the same way that the concept of set may be seen as an organizing principle for the mathematical universe. The purpose of this book is to explain this remark.

Also, check the comments here in WP: they’re quite interesting too!

About these ads

11 Responses to “Everything is dynamically typed”

  1. Cale Gibbard Says:

    You should get a kick out of typeclasses. :)

  2. Joseph Huang Says:

    Learn Clean. You can say this parameter can be any type that has + defined, or any other arbitrary function. Also no need for Monads to do I/O, but that’s not what you’re talking about.

  3. Top Posts « WordPress.com Says:

    [...] Everything is dynamically typed I’ve just seen David Weinberger’s recent Authors@Google talk, a deeply interesting overview of his new […] [...]

  4. Polytheism, Polymorphism, and Poly « ~Pentacles~ Says:

    [...] computers don’t have a global pickling memory space. Anyway after reading some Cher stuff I got over to this page and because she is such a hieromancer she thought she could highbrowbeat me at musing about [...]

  5. Thiago Silva Says:

    I really enjoyed reading/seen (finally) people going back to aristoteles, plato, et al. to realize the fundamentals of classification and discussing organization, having the nature of things in mind and how we perceive them. I really appreciated it.

    As for the “dynamic type” discussion, I find very appealing Kay’s speech. First of, it is of my understanding that classifying an object is making a compromise with how we perceive the object at a given moment. As our perception changes, we might find out latter that the taxonomy must be modified. Since our perception changes constantly, inflexible classification is, by itself, a huge problem. Of course, I think that would be the case as well with static typing.

    Other line Kay says that strikes me in the deep is about constructing complex systems. I think it goes something like this: finding out how things interact with each other (rather than precisely classifying the things) is what makes possible to build and grow complex systems.

  6. matthias Says:

    Bob Harper’s agenda is internally consistent, beautiful and therefore appealing but it’s the pragmatics that matters.

    As for pragmatics, take a look at Typed Scheme from PLT. It is an explicitly typed language that we constructed over the past year, with the goal of porting systems module by module from an untyped world to a typed world. Naturally as you port your systems, you want to change as little as possible, granted that you have to declare types for function headers. One thing we therefore do accommodate — in a type-safe manner — is the idea that a variable (function parameter) can assume different types in a function body. Specifically, the type depends on the control dominator of the variable (which predicates dominate the flow of control to the variable occurrence). So you have categories yet they are flexible.

    Thus far we have ported a few thousand lines of code — small scripts (100-500 lines), medium size libraries (300-1000 lines) and an application (some 3000 lines). The person who ported the programs is a student who hadn’t programmed in Scheme before. It is amazing how easy it is for him to port code and how little code he has to modify or add. We are pretty sure that the code base is representative but we are in the process of conducting additional experiments. We’ll report this somewhere and hopefully soon.

    The conclusion I can offer after 20 years of soft typing research is that many dynamically
    typed programs do satisfy a type discipline but it is *not* the one that static typing would
    superimpose on dynamically typed programs. These things are as practical as Turning machines, so take appropriate statements with a huge grain (ocean?) of salt.

  7. Mark Miller Says:

    Enjoyed the videos! I especially enjoyed Weinberger’s analysis of traditional vs. internet information/news media. I think he is right on. As for tagging creating stuff that’s more findable, I think the jury is still out on that. I think things are definitely more findable than through the traditional card catalog, but at the same time I still run into situations where I’m struggling to find something on the web.

    I’ve seen other presentations by Kay, so I’m usually familiar with most of what he discusses. He’s always good to listen to though. He continually amazes me. A couple things he said were prophetic in this video. In the midst of the “browser wars”, he predicted that Microsoft would not take over the web. Nor would Java/CORBA, and he gave his reasons. He also gave the keys to “the semantic web”, conceptually, which has been a hot topic over the last year or two–but this was 10 years ago. When he talked about “every object having its own URL”, it made me think of REST, at least what I’ve heard about it. Even though he said, “This is something that will need to be worked on over the next 10 years”, it’s something we’re still working on.

    As for static vs. dynamic typing, I refer you to an article you linked to a while back, called “The Art of Lisp & Writing”. I really enjoyed that article, incidentally. I commented to a friend several months ago that writing code in Smalltalk “felt like writing”. I’d say the same about Lisp, though I need to get more familiar with it. Richard Campbell said that the problem with statically typed systems is they force you to make decisions early, and the problem with that is there are not only the domain-driven requirements, but there are also the system requirements that are realized once the system is built. You don’t realize them until then, so it’s better to work in a “medium” that is maleable. It’s much harder to change things in a statically typed system. He said it’s better to introduce static typing once you have a mature product, when you want to “lock down” certain aspects of the app. Just a guess, but it sounds like this is where mattias’s suggestion about Typed Scheme comes in handy. The thought that came to mind for me when Campbell said this was the Groovy language. It allows a spectrum of development ranging from complete dynamic typing to pure static typing. In fact you can use Groovy to program in straight Java if you want.

  8. Kyle Lahnakoski Says:

    I believe…

    David Weinberge is advocating multiple classification systems; each useful for it’s own purpose. Classification is useful, as it speeds understanding by associating with similar objects. Albeit multiple classification can seem more complicated, it is rare to need more than one classification for any given purpose; leaving the user with only one relevant classification.

    Extrapolating David Weinberge to programming: He is saying the class hierarchies are the Dewey Decimal system in programming, and we should be going to a mixin system which is more useful for our particular (and changing) purposes.

    A static typing mixin system is superior to dynamic typing for the fact it communicates more about the intended use of objects to other programmers (and the compiler).

  9. Mark Miller Says:

    @Kyle:

    As best I can tell mixins still use classes. Though Weinberg didn’t really talk about programming, I think what you are saying kind of fits in with where I think programming is heading: the ability to change representation more easily.

    Re: static typing mixins being superior to dynamic typing

    I don’t see your point. As far as I’m concerned you’re defeating yourself. You’re trying to reach a state where you can change the representation of something at will (re-classify it), but you’re using a static type system which has a tendency to lock down representation. Your goal would be more easily achieved using a dynamic type system. Even the mixin strategy is easier to implement in a dynamic language (incidentally, the mixin strategy was invented by the Lisp community).

    As for me, I find that expressing my intent is more easily achieved in a dynamic language, because I can express my algorithm using the representation I want, without type markers cluttering it up. I find that with languages that are statically typed I tend to focus more on how the computer will execute my process, and I’m forced to represent it that way. I often end up adding comments saying “This is what my process does here,” because the code is just telling the computer what to do. It’s not telling me what it’s doing. Granted, type specifiers are still valuable in some contexts, and I still use them, but I’m glad I’m not forced to use them everywhere.

    I think languages like Groovy have a future because they give the programmer a choice of where and when to lock down representation with static types.

  10. Best of Feeds - 24 links - design, tips, facebook, blogging, games « //engtech - internet duct tape Says:

    [...] [CODE] Everything is dynamically typed (jaortega.wordpress.com, 22 saves, 5 inbound links) [...]

  11. Joe Says:

    Uh, this has nothing to do with static vs dynamic typing. The difference between the two is just a matter of wether you do your type checking at compile time or at run time. They can both do anything you want to do. In your case you should learn the basics of haskell. I’ve been using it for a whole whopping 4 hours at this point and even I know that typeclasses are exactly what you want.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 42 other followers

%d bloggers like this: