New kids Go, Julia, Rust vs old boys C, Haskell, Lisp, Python, Smalltalk

Python is my Go To language of choice. It has plenty of libraries, they’re mature, and the language is expressive, quick and simple to use. IPython notebook makes Python an even greater pleasure to use, as you can code in a very experimental fashion. It all Just Works (TM). I have switched over to version 3 sometime last year, and I am pleased to say that it provides everything I need, without me wishing I had stuck to version 2. Possibly the only thing I might miss, but not currently, is Mechanize, a programmable web client.

One project that keeps coming back to me is an accounts program I wrote, which goes back a few years, but one that I update periodically. I wrote it originally in Python. Of course.

One day I bought a Raspberry Pi, which is a credit card sized single-board computer. It is very cheap, although not powerful. It is designed for hobbiest projects, mostly electronics, and runs Debian. It is cheap enough that if you fry it, you don’t mind. It can even be used as a webserver, email server, and so on. I know, because I have used it for those purposes for awhile. I can’t heap enough praise on the marvel that is the Raspberry Pi, and I’m proud to see that the engineers are British.

Running my accounts program on the Pi was slow. The program took about 45 seconds to run, which was a long time for a simple program. Python has useful profiling tools, so I was able to get it down to under 5 seconds by optimising my code.

I thought that the program was rather crufty and unmaintable, so I set about rewriting it in other languages.

Lisp is always fun to play with. I tend to marvel at all the neat things I can do with it, before, of course, going back to Python where I can actually get something done. Lisp has good modularity, and the REPL means that it is perfect for incremental design.

Smalltalk is another language I play with from time-to-time. Its killer feature is its interactive environment. It’s even better than Lisp. I always seem to destroy my images accidentally, however. It has some useful add-on packages, but often you find that they are incompatible with the image you have. Also, I find that I’ve never really been able to “grok” their object model. It’s not that Smalltalk objects are conceptually difficult to understand. It’s more how objects should be structured that I haven’t really found a good answer for.

Some kind of language that took Lisp and combined it with a modernised interactive Smalltalk environment would be a wonder to behold.

Then Go came along, and I decided to try writing my accounting program in that language. I was a little frustrated with the syntax, but I was able to translate nearly all of the functionality of my Python program into Go. Part of what my program does is to download share prices. Due to network latency issues, it is much faster to use some kind of concurrency model to download a bunch of share prices in a oner, rather than sequentially. It took me a little while to get to grips with Go’s channels, but I was proud and happy with the result.

Go seems to have trouble building on some systems like Raspberry Pi, and even Windows seemed a little off. In the end, I thought Go was a little unreliable, not particularly fast, I didn’t especially like the syntax, and I thought that it had a few other flaws. I actually think that Go is one of the least interesting languages I’ve tried. YMMV.

C programming. This is the current working version of my code. Needless to say, it’s fast. I am a newbie to threading models, but I was able to make the downloading work concurrently. Threads are often regarded as a dark art, but they needn’t be too tricky if you can isolate the relevant parts and tread carefully.

C is actually a reasonable language. Sure, your Python code will be shorter, but C isn’t “too” bad. It’s actually fairly manageable to write code in C.

I am not familiar with the latest standards in C++, but when I last looked at it, I didn’t like what I saw. I think it’s too complicated as a language. I don’t particularly like the object model. Putting object methods inside classes doesn’t seem like a win to me. Lisp showed that you don’t have to implement classes like that. I like the C model where you pass structures to functions. It works. I’m not surprised that Linus Torvalds prefers C to C++. C++ can be quite difficult to reason about from his perspective.

Java. It’s not “as” bad as i was expecting it to be. I found that I could actually accomplish many things in it, although I never tried to rewite my accounting program in it. People who like Python are probably not going to be big fans of Java. I know I’m not. Java feels just, too, “overelaborate”, with lots of accidental complexity.

Julia. A very new language, with an emphasis on scientific computing. I tried it a few times. There is IJulia, which is a notebook equivalent of IPython. In fact, IJulia is actually written in IPython. Since Julia is designed for scientific computing, it comes with some nice syntax for which Python requires bolt-on libraries. This means that Julia, for scientific computing at least, Julia is more terse. Julia is designed to be fast, and it has performed impressively on some benchmarks. The problem is, Julia is slow to start up, and when you import libraries, it has to recompile them, unless they are built into image. This actually makes it frustrating to use interactively. Having a REPL is a definite win for Julia. It even has macros, which is pretty cool. It’s a very interesting language, particularly for scientific computing, but its slowness means that it is one to tune in later, rather than now. Maybe Julia will be much more viable a year from now.

Rust is another new kid on the block. It is designed to be a systems programming language. It has notions of ownership and borrowing of resources at the language level. The compiler is therefore able to make deductions about the scope and lifetime of resources. It is therefore able to know when resources can be cleaned up. It is unlike dynamic languages, though, which require a garbage collector, introducing all kinds of problems. Rust can free resources, knowing that they are no longer needed. This has the amazing win that programs can ostensibly be as fast as C, but don’t suffer from resource leaks, access to freed memory, and all the other bookkeeping problems that C programmers face.

Rust is therefore a good choice, potentially, for C projects. Rust is being championed by the Mozilla foundation, and they seem to be keen to use it for Firefox. Firefox is a complicated program, with resources and threads being created and destroyed all over the place. It will be very interesting to see how Rust is used for Firefox, therefore.

Will we see new operating systems being implemented in Rust?

I also see Rust as being used to implement programming languages. Could you write a Scheme in Rust? I think that would be the acid test. Scheme has a number of peculiarities which often maked it difficult to reason about the lifetime of resources.

Rust is not at version 1.0, although they expect to reach that milestone mid-year. I’m still having plenty of trouble with the ownership model, but by asking a question on Reddit, I was able to get a simple threading program working. The big problem is that nearly all of Rust’s add-on libraries are broken at the moment, due to lack of stabilisation of the language and core library layout. There seems to be significant interest in the project, so hopefully these issues will be sorted out.

So I can see Rust being used where C would have been. It’s not ready yet, so it’s one to tune in later.

Haskell is the latest language I’ve looked at. I had looked at it before, but I expect that like most people, they’ve found it mostly a big ball of WTF, requiring a PhD in computing to be able to print a string. I don’t understand Monads, what the type declarations actually “mean”, or their concurrency model. However, I find that if you start slow, and build incrementally, you can actually get stuff done. I have now made some progress in translating my accounting program to Haskell, and I’m fairly confident now that I can see it through to completion. Dunno about the concurrency stuff, though.

Despite the many false starts, I think I can actually get there with Haskell. Build incrementally! Problems with cryptic type message become more manageable (look, just print a string you bastard program!). As improbable as it seems, I can actually imagine writing more and more programs in Haskell. It seems to offer a good tradeoff of correctness, libraries, stability, and high level. Haskell offers a “kind of” REPL. But it seems like a “hybrid” one, where the interactive environment has some different syntax from library files. Nothing seem to beat Lisp in that respect, where the REPL is consistent throughout.

So Rust, Julia and Haskell are quite interesting new languages for me, and I think I’ll be concentrating on Haskell for now. Julia and Rust are ones to tune into later. Rust may show some excellent progress in 6 months, but I might wait for about a year for Julia. Golang is something I can’t get excited about.

If all else fails, Python FTW.

Advertisements

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Computers. Bookmark the permalink.

9 Responses to New kids Go, Julia, Rust vs old boys C, Haskell, Lisp, Python, Smalltalk

  1. Profpatsch says:

    Hey, nice read. Good to see there are other polyglots out there who don’t particularly fancy C-like syntax. 😛

    Actually ghci is very consistent. You might have an aha-moment once you know that it basically just opens a giant `do`-block. That’s why you need `let` for pure values and `<-` for thing coming from the `IO`-Monad.

  2. laeeth says:

    Hi.

    I found your blog when trying to find a better solution than hdf5 for storing financial time series.

    If you are looking for a higher level C, you might find D (dlang ) to be interesting. It is fast and high level if you want it to be.

    Laeeth

    • mcturra2000 says:

      Thanks. D is a language that I’ve never poked around with. I’m actually quite enjoying using Haskell at the moment.

      I’ve played around with HDF5 on the odd occasion – not without regreats, either! Using languages like C and Fortran seemed to involve a lot of plumbing.I never had so much data that HDF5 was the only viable solution, though.

  3. Sergej Trupp says:

    As python user, you might find nim lang interesting. what is you haskell performance experience? in my last try haskell was 100x slower than C but i make heavy usage of 3rd party libs.

    • mcturra2000 says:

      OK, thanks for the heads-up on “nim”.

      Rust looks like it might be an interesting language for those that like Haskell, but want performance akin to C.

      I’ve not done any benchmarking, but I’ve found Haskell it plenty fast enough for my needs. Anecdotally, it feels a lot faster than Python.

  4. name says:

    Wouldn’t Lisp and Python end up being very good with their repl’s because they’re interpreted as opposed to compiled?
    They literally feed your program into a repl-like thing, hence why they’re so good at the repl.

  5. Pingback: A newbie Haskeller revisits Rust | Mark Carter's blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s