|
I’ve been thinking about my last post, and I realized it was a bit imprecise.
See if we drill in on the axis “unsafe” versus “safe” and “useless” versus “useful” as described in the video Programming language Nirvana, Erik suggests introducing another axis that measures how precise or imprecise (or for embellishment “honest” and “dishonest”) types are in the language.
Now how exactly is this preciseness to be measured? Well the type of a method is precise if in addition to the value that is returned, it also specifies the potential effects involved in computing the result. For instance, Java’s throws clauses, or Haskell’s monads. Interestingly, if you apply this measure to dynamic languages they are trivially precise simply because they specify no type at all.
But if you take for example a property such as System.DateTime.Ticks, it is imprecise because it claims to be a long, where as in reality it is a value that changes over time, rather rapidly in fact J.
Now except for mathematically oriented languages like Haskell, which is precise, safe, and useless, most practical languages are by this definition imprecise.
So if you are really pedantic and extremely precise in your definition of “functional” programming, like say Erik, then most languages do not hit the Pure Functional Programming bar. Indeed Erik would be much happier if we agreed on a less precise word for languages that encourage a functional programming *style*. Perhaps something like “closure oriented programming” would make him happy? Examples of closures range from anonymous delegates and lambda expressions in C#, VB and F#, to even more powerful closures constructs like object expressions in F#.
Notice that a language can add excellent features that encourage a functional programming *style*. Like pattern matching which is found in both in F# and Erlang, or concurrency oriented programming found in Erlang which makes it dirt cheap to create threads, so cheap in fact that you can build clever abstractions for fault tolerant code.
Still if we return to the question of precision, one of Erik’s favorite interview questions is to ask how you might simulate one language effect with another. For instance spawning up a new thread is such a powerful effect that you can simulate mutable cells with it.
The point being that, just because you remove one imprecise language effect doesn’t mean you can’t simulate it with another even more imprecise effect…
If you want more, I suggest you check out these mind expanding videos:
Programming language Nirvana
Brian Beckman on Monads
Joe Armstrong
Joe Armstrong and Erik Meijer
Dave Thomas and Erik Meijer
F# videos
Happy viewing…
|