Java, Scala, Kotlin and .. Skiing

Posted on 21 May 2017

This is not actually about winter sports. Bear with me.

Many years ago, when I was at Edinburgh University, a fellow student convinced me to go on a weekend trip with him to the Cairngorms, for snowboarding. I had never been snowboarding before in my life, and in many ways it was a frustrating experience. Most of the weekend I spent sitting at the side of the slopes, waiting for the pain to go away. But there were some moments, some great turns I managed, some beautiful, easy slopes where I felt there could actually be something to it, and I got hooked.

So next winter, I went to Switzerland to learn snowboarding properly. It was a university organized trip, with some skiers and two groups of snowboarders: beginners and advanced. I joined the beginners group. My one weekend of previous experience had already given me a head start over the ones that had never even had a snowboard on their feet before. So I felt impatient and always looked out for the ones from the other group, and tried to imitate what they were doing. I mostly failed, though, so quickly I grew somewhat annoyed about the whole thing. Turned out I was not the only one. There were some experienced skiers in my group, who were curious about the snowboarding alternative. But some of them, after only one or two days, regretted their decision and just went back to skiing.

So what does all this have to do with programming? We’ll come to this in a second, just one more thing. So when I tried, with only two days of experience, to copy the relaxed, seemingly effortless riding style and jumps from the “pros”, I fell a lot. A lot. It hurt. I blamed it on the snowboard, the mountains, and not least on the teacher, and basically told him that this whole course was shit and snowboarding probably not for me. He listened to me, calmly, and said: “The guys you’re looking at have been riding for years. Because you tried to ride like that once and it didn’t work out, doesn’t mean it never will. What did you expect? That you don’t have to practice, don’t have to learn, just get on the board and do immediately what took them a long time to achieve? I can see you have talent, but you’re too impatient. It’s a journey, not a flip of a switch. Give it time.”

I followed his advice, and went on to be a somewhat solid boarder. I had a couple of deep powder snow rides in my life that were so amazing, my body still releases endorphins when I think of them today.

But on to the real topic of this post:

Scala is snowboarding. If you try it out, give it some time. If you look at the source code of some library you use and don’t understand it, don’t get frustrated. The people who wrote it are no more or less smart than you. It probably took them a lot of practice to get there. If you keep at it, your understanding will grow and you will see a lot of things under the surface, that you didn’t notice at first sight.

Java is skiing. The experienced skiers that try snowboarding are especially prone to frustration, because it makes them feel stupid. You already know how to get down the mountain, probably very fast, too. Maybe you even go down black slopes with ease. But on a snowboard, you are set back to beginner level. A slope that would be no challenge to you at all on skis, suddenly becomes a struggle. It feels like the snowboard is just trying to humiliate you. It isn’t. You have to let go. You have to unlearn some things you learned, because snowboarding is different from skiing. Don’t try to force your skiing moves on the snowboard. Its patience will outlast yours.

A skier trying to snowboard is like an experienced Java programmer looking into Scala. You think you know how to do it all, after all you’re a skillfull software engineer. But all the things you thought you knew don’t work as you want them to in Scala. If you don’t get into a Scala mindset, and just keep trying to use your ifs, fors and returns as in Java, the easiest things become ridiculously hard, and suddenly you’re not able to write a simple class anymore. Give it time. Be prepared to unlearn. Embrace the snowboard’s unique characteristics, don’t fight them.

Kotlin is carving skis. Much more modern that the old straight ones, and you can carve like a snowboarder. On the slopes, it might be just as well. But if it goes into deep powder, you still have to jump at every turn like a skier, you don’t have the amazing gliding experience of the board rider that seems to fly over it.

Deep powder snow is Functional Programming.

Skiing has been around much longer than snowboarding, and will probably never go away. Maybe a snowboarder will always be a bit of an outsider. But when he’s gliding on top of the deep powder snow, he just smiles, being happy that he didn’t miss out on this, and he never wants to go back to skiing.

Clojure looks weird, but sometimes also very elegant. Based on Lisp, it has really old roots. Clearly it’s Telemark skiing.

Google/Android is the International Ski Federation. They never quite warmed up to snowboarding, but happily embraced carving skis.

If you'd like to learn Scala and learning from a book is what works for you, I recommend to get one of these two:

Programming in Scala by Martin Odersky et al.
Programming Scala by Dean Wampler