Roads Less Taken

A blend of programming, boats and life.

Nim and OO, Part II

| Comments

In the previous article when I explored OO mechanisms in Nim I felt I dropped the ball a bit in my Fruit example. This is a followup.

In that article we first implemented some Fruit “classes” mixing methods and procs. Then I presented a cleaned up version using methods only, and a teeny template in order to reuse a base method. This template was needed since Nim currently doesn’t have a “call-next-method-matching” for multimethods like Dylan or CLOS have. This is being discussed and I think all agree that there needs to be some mechanism so that you can call a “next lesser match” of all matching multimethods.

But I also wrote that the example can be written perfectly well using generics and procs only, thus ensuring static binding and maximum speed. But the “super call” problem also existed for procs, and the template hack was just a hack. After more experimentation I now think I found the proper Nim way to do this so let’s take a look…

Ubuntu Just Works

| Comments

A friend of mine is having a less optimal experience with Linux, and I realized I could jot down my experience for the last few years.

I have been using Linux on my desktop for a long time now, about 10 years I think. Early I played “distro jumping” and used Lunar Linux for quite some time on my older Zepto laptop.

But at some point I just decided that, nah, source distros are huge time sinks. Not necessarily because they have issues, but because they are fun to tinker with. I also felt it was “smarter” to know a mainstream Linux well, so I decided to go for “least friction”, and moved to Ubuntu. When Unity hit I did contemplate using something else, at least an alternative shell, but decided to just “hang in there”, and now I tend to like it. Recently I upgraded to Ubuntu 14.04 LTS, it was pretty eventless.

Nim and OO

| Comments

Nim is presented as an imperative language. And yes, it has some of its roots in the Pascal line of languages, but it also has a set of powerful abstraction mechanisms making it very suitable for object oriented programming. And when I write “object oriented” I am referring to a broader flexible sense of OO in which objects can be formulated with attached behavior, polymorphism between different objects, some kind of reuse model of code (inheritance etc) and some type of dynamic dispatch.

Since I am a long time Smalltalker that is my main reference for “good OO” and not the … monstrous OO often seen in Java or C++. Its hard to explain the differences, but let me just say that OO in Smalltalk is elegant and natural, very much like in Ruby or Python - but ever so more streamlined. Smalltalk is a dynamically strongly typed reflective language with a heavily closure based style.

In this article I will try to make “sense” out of how to do OO in Nim.

Nim Socket Server

| Comments

In learning Nim I decided to implement a trivial Socket server, very small, as an example. Its not a useful HTTP server (it just returns a hard coded HTTP response so we can benchmark it using HTTP tools), and its not async - there are other such examples in the Nim examples directory and in its stdlib. No, I wanted to write a more classical threaded socket server to see how easy that is - especially with the new APIs in Nim “bigbreak” - and see how it performs.

The new “bigbreak” branch that will become Nim 0.10.0 soon-ish has a bunch of new stuff in the networking area. Its replacing the single sockets module with a low level rawsockets module, and a higher level net module. And there is a new selectors module that abstracts over different modern IO polling mechanisms. This means that a single API will use epoll on Linux, kqueue on BSD/OSX, old select on the other Unices and IO Completion ports on Windows. At the moment epoll, select on “other Unices” and IO Completion ports works. kqueue is on the todo.

So without further ado…

I Missed Nim

| Comments

A year ago I wrote an article trying to round up new languages since year 2000 and what I think of them by just… glancing at them, or otherwise playing with them. I ended up sifting out the 4 most interesting in my not so humble opinion - Go, Rust, Dart and Julia. Now a year has passed and…

I discover that I missed Nim(Nimrod)!

Nim was born somewhere around 2006-ish and is clearly a very serious language to consider, but is going suspiciously under the radar. Having reviewed this language more closely (and still doing so) I can safely say that for me it actually easily tops this list.

I have already posted a few articles about Nim, but this one is meant as a followup to that article trying to make amends :).

NOTE: Technically Nim is still called “Nimrod” up to and including the 0.9.6-release that was done yesterday. But for the upcoming 0.10.0 and onward its Nim. Short and sweet.