3 ms·
I love the work of the PLT group, and wish I had time to give this a better read right now. Barring that, I'll just waffle on related topics. Having worked for
by noelwelsh 11y ago
I love the work of the PLT group, and wish I had time to give this a better read right now. Barring that, I'll just waffle on related topics.
Having worked for about a decade in dynamically typed languages (mostly Racket, with a bit of Ruby and Python) and about the same in modern statically typed languages (mostly Scala, with a bit of O'Caml) I've come to believe that the use of types is more a cultural issue than a technology one at this point in time. Let me attempt to explain.
Working in Scala I've come to lean heavily on abstractions like applicatives and monads. When I design systems I now find I naturally break them down into these building blocks. For instance, a stream processing system I've been working on is an applicative functor (though I considered alternate designs that are Kleislis). Error handling is usually a monad. The meaning of the names doesn't matter. The important point I'm building systems by sticking together patterns. The patterns are different to OO design patterns as in the Gang-of-four book, but the core idea is the same.
When I was more into dynamic types I didn't lean on patterns so much. I tended to hand design the abstractions in each component, and they didn't always fit together so well as a result. Why the difference? I have a few thoughts.
Firstly, I've learned more with time. That's undeniable. But, more importantly, functional patterns have a different feel to OO patterns. They are much more precisely defined, with algebraic laws covering their interface. This makes interoperation easier as the interface and its properties are given. They are also a lot more general, in my experience, than OO patterns. Monads are famously general---so difficult to pin down that many people, including me at one time, struggle to see the point. This gives them great power, though.
Finally, FP patterns like monads are just about unusable without a (modern) static type system. I should know---I implemented a monadic library in Racket and debugging it was a total nightmare. I would find it easier now that I am more experienced with such things, but I believe the clarity enforced by the type checker was critical to building the mental model I now use.
This clarity of "thinking in types" is something I started to develop while using Racket, and I found as I went down that route more and more of my code became easily typeable with a classic ML style type system. I came to see a lot of my old code as rather goofy and ill thought out.
So this gets to what may the point (but I'm not sure; I'm kicking this from my head). Python, Ruby, and friends are culturally old languages. They were formed in a time (early 90s) when getting hold of PL research was hard. The look back to the OO languages of the 80s for inspiration, for the most part. It's also the case that statically typed FP wasn't really viable till about 2005 or so. That's when Scala came on the scene, and Haskell started to get enough libraries to make it usable. Also the techniques used in modern statically typed FP are surprisingly new. "The Essence of the Iterator Pattern" is 2009, for example, and techniques for monad composition is still an active area of research.
I think we're really seeing a cultural shift. I'm old enough to remember when OO was the new hotness. Java being fully OO was a big deal in 1997 when I first heard about it. The primarily OO languages now feel to me like they are the past. As FP knowledge becomes more widespread (and particularly as CS students graduate having learned about it) it's beginning to take the place of OO. When more people understand, say, algebraic data types I think we'll see less need for gradual typing. More people will have the mental model of statically typed FP and write code that doesn't need dynamic typing. On the flip side I don't know that a language community like Python's can ever entirely transition to a new paradigm.
Finally, I don't think FP is a silver bullet, though it does bring genuinely new and useful stuff to the table. Nor will we all switch to Haskell. It's the nature of the industry to build on the past, which is why languages like Scala with a strong backwards-compatibility story are successful. We're certain to take something from OO into the future, but I expect we'll be seeing more from statically typed FP and I'm not sure where gradual typing will find its home here.
<WALL OF TEXT OVER. THANKS FOR READING!>