Elm rewrite - Is this the beginning of the end?
Catching up
I can’t believe it’s been one and a half months since the last post. It feels like the jasmine testing, the two week sprint, all that inventory stuff, buy/sell, ReactDnD, pack capacity, coins etc… happened in another life! It’s been a pretty incredible 6 weeks with some highlights:
-
Work - Has been awesome to put it in one word. The teams are good at what they do, fun, positive and the whole vibe is great. Still early days yet, and there’s this part of me that says it can’t stay this good… surely. So I’m enjoying it whilst it lasts. I think it’s a deserving break from the more recent stint at Panda City!
-
Cycling - I’ve taken up cycling to work. It makes me want to get up in the morning and gives me energy going in and coming home! It’s actually quicker than public transport and much healthier than sitting in a metal box with wheels for an hour each day. Truly, it’s the shits!
-
XCom2 - I’ve finally finished the game and can move on with my life. There’s one important take away from finishing the game though. And that is, learning to accept total and absolute devastating failure, getting back up and moving on. The game is either too boring (non-ironman) or unforgiving (ironman). I almost gave up out of tedious boredom from my non-ironman run because I was reloading everytime the game got hard or when my soldiers were killed. Ironman taught me that life in the game is just as unfair as outside the game. Playing it in ironman, I felt the excitement of going into battle, the utter despair of losing a whole veteran squad to a badly placed unit and it saved the game for me. This is something I want to bring to Castle of the Winds.
-
Unity - A couple of old high school friends got back into contact as they wanted to make a game. We’ve settled on Unity3D and I’m splitting my time now between this project and a top-down shooter. This actually means that I’m making educational games at work, a turn based RPG at home and a real-time shooter with friends… two months ago, if I was asked what I’d be doing now, I’d probably have said, contracting for some boring corporate earning bucket loads of money or at a digital agency making websites. It surprised me to find myself where I am at now but it makes me content that I’m finally having a go at what my naive youth dreamed about all those years ago. This is my time.
-
Elm - So we come to this. Wait this should be a title…
Elm
I know what you’re thinking. Is this guy serious about finishing Castle of the Winds or is he just going to keep rewriting the basics of the game in every new javascript framework that comes out. No? You weren’t thinking that? Well, I was. In fact, I think about this alot. My first publicly documented attempt was here then I started a Meteor/Blaze version but had to rewrite it in React which is this project and now I’ve completely dropped the language. This isn’t a framework change, it’s a language change.
It all started when I was having a chat with this random guy about a new language I’d been keeping tabs on for a while. This random guy just happened to be a older tech lead and I’ve been impressed with his leadership style and how he’s kept abreast of upcoming technologies. He went from ‘oh yeah, I’ve heard of that language’ a month ago during the interview to ‘yeah I’ve written two board games in it’. A combination of that and the fact that Elm 0.17 just came out with a language restructure caused me to put cotwmtor aside to have a look at it.
Words cannot fully describe the next few nights of euphoria as I explored the language. Elm transpiles into javascript and can be run in the browser like any SPA, but it’s very different to javascript.
-
It does not throw runtime errors - Zero. No exceptions. No undefined variables. No type cohersion errors. My total time spent debugging has been at about 0 seconds.
-
It is typed - I mean that if I declare a value as a Weapon, I can’t fit that into anything else. It’s going to be a Weapon and will error during compile if I use it in any other way. This gets rid of a whole class of issues in javascript where I could have added some additional properties to an object and then it breaks a bunch of other functions during runtime that I won’t even encounter until I’ve tested those code paths.
-
It is pure and functional - Pure functions makes alot of sense to me, you have inputs and you have outputs. They do not hold state. They are predictable in their outputs, if you put in the same inputs, you’ll get the same output. This way of thinking is very different to how I’ve coding in the object orientated paradigm for the last decade. Althought I’ve dabbled in it from time to time, it feels great to finally take the leap directly into a functional language.
-
Workflow - This has been the most amazing part of working with Elm. In every other language I’ve used (C/++/#, Java, js/ts/cs, etc…) the workflow has been Think -> Code -> Test -> Debug -> Think … Elm takes the Debug stage out so it’s just Think -> Code -> Test -> oh it just works, next feature. I think the reason is that Elm forces you to consider every possible outcome of a pure function. It’s almost like another language that I used before called the B-Toolkit where you’d write mathematical expressions and then proved that they were all correct. In Elm, you have to handle all cases of inputs and outputs of a function, and as programmers, it takes years to get good at handling edge cases but in Elm, the compiler forces you to do this up front and tells it to your face: ‘Hey! You forgot to handle this case!’ It doesn’t do it for you but it makes sure it knows exactly what to do for every possible outcome of your program. So when your program compiles, that is literally the last step, then it’s just some sanity checks to make sure things work.
What does the future hold
I think moving to Elm is an investment. Moving to using jasmine tests sped up development because I could find regressions in the code from new features or refactoring much faster. Moving to Elm has just put me on another speed curve. In the last two weeks, I have completed the splash, char creation and map screen. I’m hosting this on cotwelm.herokuapp.com. This is with learning the language for the first few nights. Productivity has been insane! I’m hooked on this like meth. Well, not meth, I don’t know how addictive that is, but let’s put it this way. When I want to unwind after a long day at work, instead of opening up a game, I get a feature out in Elm and get a rush of pure joy at it working the first time.
I’ve updated the trello board. I’ve taken shop, buy/sell and inventory/equipment back to the features list. But I’m confident that in the next month, all this will be completed. If I can move at this pace, there is a very good chance I’ll be able to complete this game before my tech lead gets onto the next cool language.
Watch this space, there are some other exciting announcements to come soon!