nosewheelie

Technology, mountain biking, politics & music.

A debate about type systems

with one comment

Jay Fields (someone whose comments I’ve come to respect) ignites yet another debate about type systems in Static typing considered harmful.

Given a good test suite the return on investment simply does not justify the use of static typing.

In 5 years, we’ll view compilation as the weakest form of unit testing. — Stuart Halloway

Type verification provides very little confidence that an application works. The little confidence it does provide comes at the cost of being confined by the type system. Verifying types is better than testing nothing at all. But, only verifying types is insufficient for application development.

Now I don’t know a great deal about type systems [1], but I know enough to know that the arguments going around appear to have been formed without knowing a great deal about type theory and what a good type system can do (I’ve heard it called arguing in a bubble).

Phillip Calçado takes it further in Static Types for Long Feedback Cycles?, noting that there has been a debate amongst ThoughtWorkers about this issue. I feel that Phillip also draws some invalid conclusions, such as asserting that a type system cannot ensure that a class fulfils its contract [2]. One of his commentors, David, makes the same comments that I’m making, that a lot of this debate stems from a lack of knowledge about what a type system actually is, talking about more advanced type systems that those we may be used to in our day jobs:

Of course I’m not talking about shonky rubbish like Java or C#’s type system but rather languages which have Hindley-Milner style type systems with inference like Haskell, ML and what not.

For a more reasoned post about this see Ricky Clarkson’s Stop Sitting On The Type Fence. The post is getting a bit old now, and Ricky’s been active in the Scala community, so I’m not sure if he still holds all these views.

My take on all this is that it’s possible to have your cake (static typing) and eat it too (all the goodness that dynamically typed languages provide). To take Scala as an example (Haskell would be better, but my knowledge of it is limited), you get static typing with type inferencing (albeit moderately weak ATM), so a lot of boilerplate goes away. You also get flexibility in the language, so you can write funky DSL style code till your heart’s content. The only thing you don’t have in Scala (as compared to Ruby) is decent metaprogramming, though I’m told there’s work in progress on this front.

For those that want to explore this a bit more, see What To Know Before Debating Type Systems and Types and Programming Languages.

[1] I know enough about type systems to be dangerous.
[2] Actually this is probably technically true, you’d need a theorem prover to do this, and potential need to solve the halting problem, but, we can get closer in practice than say Java’s type system.

Written by Tom Adams

February 7th, 2008 at 1:53 pm

Posted in Languages

One Response to 'A debate about type systems'

Subscribe to comments with RSS or TrackBack to 'A debate about type systems'.

  1. Hi, Tom,

    Yes, basically I’m talking about Java (and C# and other pop static languages) and ‘enterprise systems’ (not math or scientific applications of any kind) just because that’s where I have experience.

    Anyway, in the first link you sent he author states exactly my point about typing system != design by contract:

    Both a and b can possibly be null, so what happens if null is passed? Er, you get a NullPointerException. Some programmers will specify that in documentation for the method, or just write that null is not allowed. The same method in Scheme would be callable with any values at all, though it would fail. That changes the attitude of calling programmers. Instead of looking at the half-hearted type signature, and seeing that null is a possible value, the programmer is more likely to look at the implementation.

    The second link is very interesting and mind blowing, but still doesn’t add much light into this debate, I think. Actually I got the impression that, as the author says about problems that are for dynamic vs. problems that are for static, business software development may be something for dynamic languages. Don’t know, just thoughts.

    As I said I focused on the type system implementations I know and reading the links I got the feeling that most nice features from static typing languages are, actually, features from the language and not from the fact that they’re static typed (and that’s probably why Scala and Haskell are always the only implementations of static typing people use in the debate). I never said that you can’t create a good programming language using static types, my point (and I think that Jay’s also) is that static typing ‘per se’ won’t give you an advantage in the scenarios described above.

    I also said that I can’t think about scenarios where static typing would be better but it’s not because I can’t think of one that they don’t exist ;)
    I’ll add a follow-up in the bottom of the post clarifying these points.

    Thanks for the links, added your blog to my readings.

    cheers

Leave a Reply