Having some adventures trying to write a game in a functional manner. I've picked Clojure to do it with so it's meant learning a lot of things and being relatively unproductive for a little while. Is this a useful way to spend my time? I don't, it's certainly interesting though. You join me as I'm struggling to get a productive work flow going in a language I don't really understand using tools I've never touched before :)
I think I'm starting to get there with an efficient work-flow and work environment. It's taking a little hacking to get there though.
I'd got to this point:
- Installed Leiningen
- Utility to create and manage a clojure project
- Will mamage required libraries and their dependencies
- You can specifiy what library versions you need
- Will download everything you need, run your project, boot up a repl, etc
This was pretty good but each time I edited a file I was quitting and rebooting the repl. Clojure runs in the JVM and that takes a while to reboot. I don't know much about lisp like languages but one thing I do know is dynamically updating their code is something they're renowned for and I shouldn't be working like this.
So now I've started using emacs and a package called nrepl. It's meant a pretty steep learning curve getting used to emacs but from the quick research I did it seems that no other editor has clojure live coding support anywhere near as good. I've had to learn about:
- Package installation and management on emacs
- A bunch of new and horribly obscure key combinations
- What ido-mode is
- A bunch of tmux tricks
And it's working really well. Now I can boot up a JVM and instance of my app from within emacs and create a repl that I can interact with. So what if I change my code? Turns out I don't even need to save the changes. All you need to do is ask emacs to evaluate your buffer and any changes you've made will be inserted into your code. It's quite amazing to be honest.
I'm only at the position where I'm making a change and then executing a function in the repl to test my change. It works well. Next up I want the repl to be making changes to a running app.
There's definitely something the air about functional languages right now. They have the promise of being able to efficiently handle large data sets across loosely connected computing resources. In fact there's already a bunch of applications on the web that do exactly that.
IMHO that's what we'll have on our desktops in 5 years time; a box with a shit-load of loosely coupled but highly powerful computing cores. Shared memory is an illusion we're currently clinging onto and at some point we'll give it up and have to work with computing devices that are inherently fractured in design. We'll need different programming paradigms to be able to do that well and it's functional languages like Clojure, Haskell, Erlang and others that seem to have a handle on this.
This is weird, John Carmack announced he was trying to write a game functionally using Haskell. And the game? Wolfenstein 3d :D Wow. I'll get a lot less done that him with far few insights but it should be a fun journey and I'm really interested to see the path he takes :D
- Clojure - lisp like language running on the JVM
- Emacs - *nix editor with a religious following
- tmux - modern day version of screen
- leiningen - package manager and much more for clojure. As npm is to Node.js
- Carmack's exciting news - he's writing Wolf3d in Haskell
- Erlang : functional yet practical language designed by Ericsson for high bandwidth / reliable telecoms applications
- nrepl: Emacs excellent clojure repl package