Encapsulation may be in the eye of the beholder

May 28, 2009

Here is an interesting question: is getloadavg() a more or less encapsulated way of getting the load average than (on Linux) reading /proc/loadavg? I wound up thinking about this in the aftermath of feeling rueful about discovering Python's interface to getloadavg(), and I don't think it's as simple as I made it out to be in my original entry.

For me, what it comes down to is different perspectives. An interface like getloadavg() is nicely encapsulated for someone who can easily use the C library; you get an interface that works on any system that supports it. But for someone using alternate languages like Python, Perl, or Ruby, a file as an interface is much more accessible than a something that's wrapped up in the C library, and thus the interface it provides is much more abstract and usable. You would much rather be able to get the information by just reading a file than have it only available if you can figure out how to call a new C library function.

(I would go so far as to say that a new interface that is only available by calling a C library function is not so much wrapped up in the C library as locked up in the C library.)

So: from the perspective of getting the load average on a lot of different Unixes in a C program, getloadavg() is more encapsulated. But from the perspective of getting the load average from a lot of different environments on a Linux system, I'd argue that /proc/loadavg may be more abstracted and encapsulated, since it's available to everything and you use it just the same way in all of the languages.

Written on 28 May 2009.
« Hosted servers, cloud computing, and backups
The cost of program energy efficiency »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu May 28 01:20:01 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.