More languages: Nim and Elm

This week I’ve been looking into other languages.

Nim

I started with Nim which  has a python-style syntax, and compiles to C or JavaScript.

I’m not a huge fan of space-is-important languages since I think it makes it harder to make your code pretty, but I am actively trying to do something new here. Perhaps if I try it, maybe my worries will not be justified! Certainly tons of developers use python (and I do from time to time at work) so perhaps if I tried working with it, that will allow me to see the benefits.

Compilation to multiple platforms is also appealing, since that means I’m not limited in the future if I want to, for example, distribute on Steam.

The installation experience was simple and easy for Nim and I managed to get a basic program up and running quite quickly. But it quickly became quite apparent that this wasn’t the right choice, as I did not find it easy to produce a JavaScript output. It felt to me like the focus was much more on C output. That’s fine for their project, but it really doesn’t suit my aims, so I decided there’s plenty of other choices and I should move on.

Elm

Next on my random list was Elm. This is another functional language that outputs to JavaScript. It seems to be quite practical, with a focus on speed and type safety.

I was impressed with the Elm tutorial pages. Unlike the propaganda-laden ClojureScript, there was not a constant theme of how great functional languages are and how anyone who would use an imperative language is an idiot. Instead the tone was informative and practical, and the pages simply told me how things worked in a Elm program. I also liked the practical advice that was added alongside.

I followed the tutorials, skipping or skimming over bits that I understood, and quickly got to a state where I had merged and extended two of the examples and made a web page that shows the current time, has a button to press that does something, and counts up how many ticks have gone by.

This is great – this is exactly where I need to be for my game, and within perhaps two hours of the install.

So I think I have something I can work with. Elm meets most of my criteria for a suitable language, although I’m slightly concerned that it’s not a widespread language. Hopefully that won’t matter too much, though. It does have the bonus aspect of being something completely different for me – I’m looking forward to seeing how I can make a functional useful program out of a functional language!

Next Steps

Over the next few days I’m going to try to make a basic game loop with two interface buttons:

  • One to send my witch character off collecting herbs – this will trigger an action that takes a small amount of time and herbs will arrive after that
  • One which plants herbs in a herb garden which will automatically produce more herbs over time.

Leave a Reply

Your email address will not be published. Required fields are marked *