Monthly Archive for December, 2008

Happy New Year!

So we come to the end of yet another year. I have my resolutions and they include some exciting plans for this blog. Thanks to all the readers for staying with me! To finish off in a great note (and with a sneak peak of what is to come), here is a song I recently discovered, and consider the perfect christmas song, which reflects the modern spirit of such celebrations. As the band describes it:

“’It’s Christmas…’ is about people deciding to be pleasant to one another for about a day, regardless of whether or not they actually get along the rest of the year. There’s the same fallout after christmas as perhaps a night out where you end up in someone else’s bed – the next day, after the drink has worn off and the warm lights are turned off, everything’s just as shit as it was the day before and that feeling of comfort disappears. I feel like i have a similar relationship with christmas as i do with booze. Each make me feel nice in a fairly false way, and they are really the only two things i actually spend money on, aside from food. It’s also about that total indulgence period, which always comes with the promise that you’ll eat less, drink less and spend less really, really soon… always tomorrow. I feel it’s maybe healthier to live a little more consistently (not that i do), but often humans need excuses to be nice and giving and loving to one another, and Christmas is one of those times, for better or worse’.

(from FatCat via Wikipedia)

Frightened Rabbit – It’s Christmas So We’ll Stop (2008 version):

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

I totally agree that that is how such celebrations remain important and significant for most people, even when their original meaning was lost. So let’s make it our resolution to keep some of the positiveness of this season alive throughout all 2009, so that when Christmas comes, we’ll be motivated to be even better!

If you liked this, check out the amazing choir version and the rest of their work, it’s a fantastic band.

Happy new year!

Opening up the borders
(or, how I learned to stop worrying and love the FFI)

I thought I’d write about something that I feel people are a bit too scared of doing, which is binding a foreign library into their favourite language. We all have our own strange favourite language in which programming comes out more naturally, faster and more correctly. However, I sometimes found myself hitting bumps when I wanted to use a certain awesome library that is programmed in a different language, and usually compiled to native binary libraries.

The usual approach is to search for bindings existing for the language, and usually there will already have been someone who made the bindings, neatly packaged them and released them for you to use. The problem occurs when there are no such bindings available, which happens more frequently for less mainstream languages (like my beloved Common Lisp). Sometimes there are some incomplete bindings that someone posted, which don’t cover all the cases. However bindings are fairly easy to do, even though they are not that easy to structure properly.

In fact, invoking and getting values back is the easier part, usually you just use some built-in construct to invoke the native procedure, and the FFI takes care of the low-level bindings, and sometimes even memory management. However, in order to feel like it is part of the language, we have to build the proper abstractions around the native calls that make it feel idiomatic. For instance, in the case of Haskell, care has to be taken to properly handle side effects, and create a pure, referentially transparent haskell function.

To make it easier, for the direct bindings one can use wrapper generators like swig. These usually consume a header file and produce a language file full of the direct wrappings of the native functions. Then, using these functions one can use the higher-level features of the language and encapsulate it in the way that we feel a library for that purpose in the target language must be like. In the end, we end up with a library that feels natural in the target language and as long as we took the relevant precautions, has all the characteristics of the language that we love.

That is all. So, next time you find yourself thinking “why doesn’t <language here> have bindings for <library here>? <other language here> has them!” don’t ignore the possibility of building the bindings. It is not as hard as it looks (and way more fun than it sounds!), and if you get them completely right and idiomatic you can even help people by publishing them.