Wandering Thoughts archives

2007-10-22

The dangerous appeal of the obvious

For reasons that do not fit into the margins of this entry, DWiki sometimes needs to get the current Unix load average. I developed DWiki on Linux, and getting the load average on Linux is really easy; you read a line from /proc/loadavg, split it into three floating point numbers, and you're done. So I wrote a get_load function that did that and forgot about the whole thing.

Then this server got changed from Linux to FreeBSD, and suddenly that code didn't work any more. (Because I had been paranoid, it didn't fail explosively; I had assumed that someday system problems might cause things to fail and coped with it.)

FreeBSD doesn't have a /proc/loadavg; instead it has a getloadavg(3) function in the C library. I gloomily contemplated how to make a C library call from Python, and on the off chance someone had already written an extension module to do it I did a Google search on [python getloadavg].

Which promptly turned up the general and supported Python function to do just this, os.getloadavg(). This not only solved my problem but would have saved me the effort of writing my get_load function in the first place, if only I had thought to look for it instead of leaping on the obvious way of getting the load average on Linux that I already knew about.

This is the dangerous appeal of the obvious: just because I know how to do something doesn't mean that I know the best way to do something. Maybe I should keep looking slightly harder, just to make sure.

(You could say my issue with rounding up was the same effect in action, although it was less obvious to me then.)

python/DangerousObviousAppeal written at 21:42:03; Add Comment

Vim options it turns out I want

This server recently moved from Fedora Core 2 to FreeBSD, and in the process I discovered that I had quietly become addicted to a few vim features, despite past dislikes of overly intelligent things that call themselves vi.

(I am pleased to report that the default FreeBSD version of vim does not behave that way.)

So it turns out to be necessary to set a few vim parameters to get it to behave the way I want. For my future reference, here's what I've found I need to set in $HOME/.vimrc so far:

set nocompatible
This is the easiest way to get multi-level undo, which has become my single must have, cannot live without it vim feature. (I should have expected this; I already knew that multi-level undo was addictive from using other editors with it.)

set backspace=indent,eol,start
I have also gotten used to being able backspace over anything, end of line included.

let loaded_matchparen = 1
This is one of those anti-features; I do not want vim to be freakily super-intelligent about (allegedly) matching delimiters.

I still sort of want vim to behave like basic vi, but apparently missing these features is now too basic for me. Such is the corrupting experience of using Linux, with its array of convenient extensions and GNU this and that.

(I care about this partly because I write most WanderingThoughts entries on this machine in vi, mostly out of inertia and habit.)

linux/VimOptions written at 20:48:52; Add Comment


Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.