Knowing Scala (Intermission)

I’m getting to the point in my Scala understanding where I’m making small commits to our Very Important Project at work. I ended up wasting four hours of work the other day because I put stuff in the wrong place and then spent a lot of time reorganizing things. In the context of FP, which puts such an emphasis on composition, “reorganizing” seems to this learner more tedious than reorganizing an OOP program.

Where to put your stuff” is a big deal for a programming paradigm, and it seems to me that OOP is significantly better than FP in guiding you towards structure. The FP proponents are always talking about keeping things small, but a real system is going to be large and it seems to me that OOP class structures provide a lot of guidance.

Since my organization has chosen Scala as our language, I can use OOP. But when you’re learning the FP mindset, there’s so much emphasis on compressing functions and minimizing your working set that it’s very natural to make a mistake, and write a series of functions that combine to do the operation at hand only to realize (as I did) that if only you had located the function over here, in this class, you could write fewer functions, with simpler combinations, to accomplish the same goal.


I always try to remember my experience learning OOP. I was a C programmer and had just been hired as the Product Review Editor at Computer Language Magazine. OOP was the hot new thing and I installed a brand new copy of Smalltalk/V 286 and diligently worked through the tutorial (which involved turtle graphics, as I recall). Everytime I had a few minutes I’d sit and try to understand “where the main() is.” And I just didn’t get it. I could type in code and it would work but I just had no idea how it was supposed to help my programming.

After about six weeks I was panicked, thinking “OMG, I don’t understand this subject that’s the topic of more and more of our articles.” I decided to break the shrink-wrap on Zortech C++ (the first C++ compiler for DOS) and simply use C and laugh knowingly every time someone mentioned OOP. And from almost the first minute of firing up the C++ compiler, I got objects. What had been obscure in a pure environment was crystal clear in a hybrid environment where what had seemed like obscure topics could be applied to the everyday challenges of writing C code.

And even more interesting, after working in C++ for awhile, when I fired up my Smalltalk environment again (perhaps for the Smalltalk/v 386 release), I absolutely loved it. It took C++ for me to understand the programming value of OOP and, once that was internalized, the environmental benefits of Smalltalk were many and obvious.

I try to keep this in mind with Scala. Right now, I’ll admit to not feeling enthusiastic about Scala. I’ve yet to feel “Oh, I couldn’t have done that in Ruby” while it seems like I bump into type-system limits and syntactical weirdness quite often (the type-erasure of generics in the JVM seems to mean that “finger typing” is not uncommon and I’ve yet to internalize Scala’s logic about parentheses, braces, and new-lines). But, if history is a guide, perhaps I’ll return to Ruby in a few months and suddenly say “OMG, in Scala I could just…”

We’ll see.