[Weekly #20] Paradigms

I've been in my industry (asset/pipeline stuff in games) for 12 years now, initially doing very imperative stuff in a language called MEL, and for about 6 years now trying to do OOP stuff in Python. In the last year or two I've been learning FP, especially through Haskell. It's been a huge eye-opener. It's been so much better for me, that I actually lost all interest in OOP.

There were a few projects I lingered on - one in particular I fought with for months, another for about 6 years, on and off - which I just couldn't make do what I wanted to do. They each got to the point that any new thing I wanted to do seemed to require a huge rewrite, or epic amounts of code. Then I started learning FP for awhile, and seeing things differently, and I've since breezed through those projects. They were very simple in FP.

I started one in 2010, and in 2014 I was no closer to getting it to work - diamond inheritance problems, locking issues, something I nicknamed ladder-inheritance (two, parallel chains of inheritance that also need to inherit from one to the other at each level), race conditions, and more than 1kloc of Python. I kept having epiphanies and trying new ideas, and always grinding to a halt again. Then one day last year I finally thought "Wait... is all of this just a simple map with a few elements in it?" I made a map with what I needed, and then wrote some functions, and got the entire idea working in 3 days. In that time I also implemented all of the things I had hoped I would eventually solve, and even a few things I'd never thought of. Everything was simple and obvious in the FP paradigm. Oh, and all of it was under 80loc - more than an order of magnitude less code. This is happening all the time for me in FP.

This could be domain-specific, of course. The kinds of things I'm doing might just work well in FP. It's always possible I wasn't doing OOP right, but then, I don't really know what doing OOP right even means, and that's after reading for a decade on what OO is all about, including the Head First Design Patterns book, and many others. Across the board, in contrast to that decade-long fight, I'm seeing FP as a paradigm with radically better reusability and expressiveness, and just a lot less code and fighting. I was always making classes and methods, and recreating the same methods all the time in OOP, but now I just do what I want to do in a line or two. In OOP I had screen-high classes (many would get up to over 200 lines), and virtually no reusability. In FP these days, I balk at functions that are more than 3 lines long, and they almost never get up to 5, and everything is useful over and over again. I'm having a lot more fun. I just wish I had that power and expressiveness everywhere. Haskell isn't available in the places I want it yet.

/r/dailyprogrammer Thread