API Emulators and Porting Layers in Dark Caves
Tuesday, May 6th, 2008If I had a $100 for every time I heard an engineer say that they were going to use a “porting layer” to keep their application “OS agnostic” I’d be a rich man. Most every software engineer dreams of writing magical portable applications that run anywhere with just a simple recompile.
I’ve got some advice for you: Set your expectations low. Very low.
It’s not that API emulation, porting layers and OS abstraction layers can’t make portable applications. There are examples where they can and do. The problem is that your new abstraction layer will likely only slightly abstract your application from your chosen OS. You can say it will port smoothly from WonkOS 6.6 to DinkOS 2.3 when you move next year… but if I were your manager I’d ask you to prove it before I invested a dime.
The problem with custom abstraction layers and API emulators is that most of them grow up in the dark and eat only mushrooms.
- You’ll also see abstraction layers that claim to enhance portability but yet have never actually been ported somewhere. You are in the dark. Who knows if it will help? How do you know it is better than just writing good portable code and fixing it in the future if needed?
- Most custom OS abstraction layers are used with just a single application: the one they were written with. It remains to be proven if the abstraction layer could be used with another application because there isn’t another one (written by unrelated authors) available to try. Is this really an application porting abstraction layer or just a convoluted method for this one application to make API calls? You’ve got feed that abstraction layer more than just mushrooms (your single application) to make it grow up big and strong.
So what should you do?
- Strive to write more portable code.
- Pick a API family that can take you to more than one OS. Pick a winner. Don’t pick some oddball micro-kernel message passing university R&D project… unless it emulates well a winner API. You’ll need more than just POSIX for many modern devices. This is one reason that I think Linux based device software platforms are on the ascent. It isn’t just the Linux API but the greater family of community software projects that become de facto standards and portability layers. GTK, Gstreamer, mundane stuff like libusb, etc.
- If you really need a portability layer than get one from a 3rd party (proprietary or FLOSS). Something that has been proven to help and has helped a lot of applications.
- If the available 3rd party options aren’t good enough why not consider investing effort to improve them rather than creating one from whole cloth?
Option 4 might be controversial but I figure that if there is a problem that more than 10 people in the world have had there is likely some sort of FLOSS project to try and fix it. Picking one of these up, enhancing it, and using it for your own project while helping the community has got to be better than doing it from scratch. At least you’ll have some sunlight and a diverse diet for your new creation to grow up in.
A non-exhaustive list of options to consider.


