Hacker News new | ask | show | jobs
by basman 4498 days ago
Your type checker catches array indexing bugs? Impressive.
4 comments

No, but Scala encourages FP, so when you:

    val fooList = List(1,2,3)
    fooList.map(...)
you'll _never_ hit the types of bugs you're referring to.

If you fooList(3), then of course you're hosed, but that's not the type checker's fault ;-)

I don't agree even with the sentiment of the original post, but there is an argument that while you can't get rid of array indexing bugs with a type checker (contracts might help here) you can design your collection types such that things like indexing above or below an array are compile time caught, as is indexing into the "wrong" array location.

Whether it is worth the trouble to do this in the type system probably depends on how good your language's type system is and how expensive array indexing bugs are to catch/fix.

Actually, in the original (circa 1968) Pascal, it did.

In Pascal, the size of an array was part of the type of the array. IIRC, You simply could not write an array index out of bounds bug. This made it a somewhat reasonable choice for a medical device, where an array index out of bounds could be catastrophic. However...

You also could not create a variable-sized array. There was no way even to talk about the type of such an object. (Yes, I ran into that professionally once.) I think this is why Turbo Pascal (and maybe others?) softened that.