On the recommendation of a fellow blogger I started reading Types and Programming Languages by Professor Benjamin C. Pierce. It's probably not very practical for the average developer; when was the last time I needed a thorough understanding of the untyped lambda calculus? But it's always good to think beyond the immediate. Here's something interesting to think about, the language quadrant:
Statically Checked | Dynamically Checked | |
Safe | ML, Haskell, Java, etc. | Lisp, Scheme, Perl, Postscript, etc. |
Unsafe | C, C++, etc. |
Languages provides abstractions against low level machine services (memory, I/O, etc.). Safe languages prevent you from mucking around with these abstractions, allowing you to program abstractly. An array is a memory abstraction; in a safe language you just need to worry about the array abstraction whereas in an unsafe language you need to further worry about all the other ways memory can be addressed.
The other axis divides languages into statically checked and dynamically checked. Statically checked languages perform type checking at compile time whereas dynamically checked languages perform type checking at runtime. While this is obvious, it is important to remember that types exists in both cases. Dynamically checked languages may infer types at runtime but there still exists types. On the other hand, untyped languages have no concept of types altogether. With assembly languages you can perform any operation on any data, since everything is just a bunch of bits.
The fourth quadrant is empty because the additional cost to perform checks on the additional operations is little; so if you're going to enforce safety for most operations then you might as well do it for all operations.
Two comments:
1) Where would Objective-C fall? Since it's a superset of C, I suppose it'd be unsafe strictly speaking, but if one stuck purely to objects and messages (and ref-counting or garbage collection) it would be safe. And although variables are statically checked in most circumstances, one can opt for dynamic typing ("id") selectively...
2) There's another dimension, type "strength" - meaning to what degree the language allows/defines implicit coercion among types.
Posted by: Reedo | May 19, 2009 at 10:34 AM