Wednesday, August 31, 2011

Apples and Oranges

In my last post I wrote I was going to do the rewrite of the game I was making together with Randy.
I did the entire server in Erlang and it was a good version. Stable, reliable, all thanks to Erlang and the way it semi-forces you to do things the right way. Especially when using OTP, which I tried to do for everything.

So which one do I like best? I still can't say. They both have their merits. I've had numerous discussions on IRC about Go and Erlang. Some like Go, some utterly despise it. But everyone agrees that there's something there.
I still like it. In the year I didn't use it, Go grew and matured a lot. Picking it up again, I must say I'm impressed with the work that was done. So I'm not going to choose a winning language, I'm going to use them both. It'll be easy too, because I'll be using Erlang for my job in the near future. That makes Go my default Go-to language (I do love the bad puns) for all my hobby projects.

I didn't give up on the whole language polyglot thing. Far from it, I'm waiting for Ada 2012 to come out so I can play with that. ;-)

Thursday, December 2, 2010

Should I stay or should I Go?

The last couple of months I've been playing around with Go. I got curious about the language because it had lightweight threads and message passing concurrency. Since the project (MUSQ) I'm working on with a friend wasn't really working out for the both of us, we decided to change direction. For both of us it meant changing languages. Randy switched to completely doing the front-end in Javascript and HTML5 with the Canvas tag. I rewrote the back-end in Go to get a feel for the language.

We're now 3 months in working with the new project. My thoughts on Go so far, I'll start with the negative points:
  • Sometimes there's code bloat. Especially when working with side-effects and you have to catch/prepare for errors, you write a lot of "if err != nil { return bla, err }". After a while the source gets crowded with it and it gets a bit harder to read. Maybe I'm doing something wrong, but for now I can't really see another way to do it. (without using up more resources)
Hmm. That's it. Can't seem to think of anything else that _really_ bugs me.
    Things I need to get used to some more:
    • No real OO. Sometimes Object Orientation is really the right way to go, and since I do a lot of it at work, it has shaped the way I think about certain things. This is not a problem, it's merely something I need to work on. The interfaces in Go are very powerful and can solve stuff quite elegantly.
    • No debugger. Ok I admit it, I'm spoiled working in VS.NET at work and using Erlang's tools. So for now in Go, it's debug print statements. It's not a big deal. If anything, it makes you think harder about what you wrote. But it slows the debugging process a bit. 
    • Pointers. This is the first language I _really_ use with pointers. You can't do pointer arithmetic so you can't do the really ugly stuff, but still, they trip me up sometimes.
    • Mutable state everywhere, especially when using pointers. Of course, it's no different at work, but compared to Erlang,... it will need more discipline from me to write clean code.
    • No generics. But how often do I actually use that anyway? Go has a lot of built-in stuff (copy, append) that takes care of 90% of the situations where I would use them. Besides, I don't think the question is "Will Go get generics?", I think it's: "When will Go get generics?".
    The good stuff:
    • First class functions, closures, feels like a functional language! (no, really)
    • Message passing concurrency. I have to say, I like the way Go does this. Channels you can pass around, limit their reading/writing depending on the situation. Very nice. Makes for very clean code.
    • The library is awesome. I only need 1 external library (for Redis) but I'm writing my own version of that and I like it better.
    • Very high productivity. I'm amazed at how fast I can sometimes write code that works.
    • Easy to refactor. What a joy this is in Go. I've encountered situations where it would take me an hour to refactor properly in C#, but it only took 10 minutes in Go.
    • It's so simple. Go fits entirely in my head. This is really important to me. I'm pretty good at Erlang, but I doubt I know the entire language, let alone C#, I don't know half of it probably. In Go, there's no obscure language feature I haven't heard of, reading other people's code is very easy. This is of course because the language is so young, but still, it's very nice.
    • I understand the stuff in the mailing list. Yeah, go ahead, laugh. But for me, this is really nice. I can keep up with the language development and not feel completely overwhelmed by the academic stuff. Good for my self esteem! :-)
    • It gives me a feeling of being 'closer to the metal'. Closer in the sense of: I've never been this close before. All the previous languages I tried are very high level. Go forces me to think a bit differently about problems.
    Go also made me think about functional programming. It's a bit strange to use languages that have no mutable state when the machine that runs it is inherently about mutable state. Ok, a functional language will hide that from you, so you can focus on writing good code. I appreciate the value in this, but it comes at a cost. Either the performance will go down, or you have to be really great with the FP stuff so you can use Haskell properly.

    In any case, as with every new language I learn, after a while, Erlang starts calling out to me. So I've decided to port the current state of my project to Erlang to compare the two. The one I like best stays. So far, Go has the advantage, but that's because my Erlang is rusty ;-)

    Sunday, August 1, 2010

    Update on my Haskell progress.

    I've spent the better part of my holiday studying Haskell. It has been an enlightening experience. I think I understand monads now. At least I get why they are useful (and necessary in Haskell).
    The type system in Haskell is incredible. I wish all languages had one as powerful as that.

    The functional paradigm is awesome. I've learned so many things over the past years, I feel I've become a better programmer. My C# code I write at work is more and more functional in nature and I believe it's more clear and contains less bugs. (LINQ is monadic, and great!)

    But it's the 'pure' thing in Haskell that bugs me. Although it's fantastic for making sure no icky stuff is going to happen in your code, personally I don't really mind that my program has unpure things mixed with pure ones. (I like to chuck in a debug 'print' statement here and there). Of course, I can't prove my code is going to run correctly. But I don't really want that either, I just want to build stuff.

    For me, Erlang provides the perfect mix between functional and practical. So I'm going to stick to that probably. (But I'm notorious for changing my mind every week, so we'll have to see about that ;-) ) Erlang is easy enough to understand completely without straining my brain. It lacks some of the fancier functional stuff (and types unfortunately), but it makes up for that with OTP. I even like the syntax ;-). Maybe I should try Prolog, or that new Mercury language. Oh, there I go changing my mind again...

    Anyway, my copy of 'Erlang Programming' arrived this week, I'm going to spend some quality time with it now!

    Monday, July 12, 2010

    Another go at Haskell

    My 2 weeks vacation is an ideal moment to squeeze in some Haskell again. I dismissed OCaml because of the GC and threading issues, but Haskell doesn't have those and is very similar to OCaml. I gave up on Haskell before because it seemed too hard. Maybe it is, I don't know, but having found the 'Haskell School of Expression' book got my interest up again. So far so good, I'm 95 pages in and all is well. ;-)
    That means for now my work on 'MUSQ' is on hold, but that certainly doesn't mean I gave up on it. I've got a whole notebook full of ideas for that game, I'm not going to let them go to waste. No more new-programming-language-resolutions this time. Just study Haskell some more and see if I can find value in it for me. And if I happen to pick a few new things up while I study, that'd be great ;-)
    Good thing there are a lot of good Haskell-resources online, it's certainly motivating to find a vibrant community in the field you're interested in.

    Friday, June 25, 2010

    Opened a BitBucket account

    For all my hobby coding adventures I've now (well, some time ago, but only blogging now) opened a
    BitBucket account.

    The main thing I'm working on now is a game called 'MUSQ'. It's a MUD-like text based adventure game that I'll write in Erlang. Development is slow, so don't expect hundreds of lines of code every week. ;-)

    I'm also reading 'Gödel, Escher, Bach' out of curiosity. I've heard so much about it, I want to know what it's all about.

    Saturday, April 10, 2010

    Erlang setup for emacs -- helper function

    I wrote a little function for my emacs setup so the Erlang stuff keeps working over different Erlang versions. I didn't want to update my config for every computer I have (a mix of 32 and 64 bit). It's written for Fedora because that's what I'm using, but I reckon it won't be much different on other distros.

    ;; ==== ERLANG SETUP ====
    (defun erlang-setup ()
      (if (and (file-exists-p "/usr/lib64/")
        (file-exists-p "/usr/lib64/erlang"))
          (setq erlang-basefolder "/usr/lib64/erlang")
        (if (and (file-exists-p "/usr/lib/")
          (file-exists-p "/usr/lib/erlang"))
     (setq erlang-basefolder "/usr/lib/erlang")))
      (if erlang-basefolder
          (progn
     (let ((lib-folder (concat erlang-basefolder "/lib")))
       (dolist (fldr (directory-files lib-folder))
         (if (and 
       (> (length fldr) 6)
       (string= (substring fldr 0 6) "tools-"))
      (setq erlang-tools-dir (concat lib-folder (concat "/" fldr)))))
       (setq load-path (cons (concat erlang-tools-dir "/emacs") load-path))
       (setq erlang-root-dir erlang-basefolder)
       (setq exec-path (cons (concat erlang-basefolder "/bin")  exec-path))
       (require 'erlang-start)
       (add-hook 'erlang-mode-hook 'highlight-parentheses-mode)))))
    
    (erlang-setup)
    

    Emacs Lisp is kind of nice, I enjoyed writing this. :-)

    Sunday, March 28, 2010

    Out with the new, in with the old!

    Ok I'm sick of it now. Too many new languages in too little time.
    Getting to know all of these languages was fun, but now I actually want to make something.
    I ported my comicgrab code to Erlang and I'm going to continue writing in Erlang. It has a nice growing community, lots of resources on the web, good documentation and books and most importantly these days; it doesn't give me a headache when I work with it for longer than an hour.
    I've blogged not so long ago that Erlang was 'too easy'. A lot of people misunderstood what I meant by that. I wanted a challenge in the form of 'solving an easy problem with a difficult to use tool'.
    Turns out all that does is give you a headache. So now I'm going to solve this not-so-easy-problem-when-you-think-about-it with an easy to use tool. Easier than all the other ones I've tried anyway. So out with all the new languages I won't use anyway, and in with the old Erlang I've already used for a couple of non-trivial things and have loved ever since.