A Curses Gotcha

10 PM December 11, 2003

For the last month or so, I’ve been ‘doing’ C++. The project is based on NCurses, an open source implementation of the curses character terminal library.

After working with Java and Python for so long, NCurses seems, well… horrible. If you make a programming mistake, the typical NCurses reaction is to print either “form library error”, or maybe even “menu library error”, crash your application, and leave the terminal in a strange mode, requiring you to type in a secret (by dint of character echo being turned off) incantation and press CTRL-J before proceeding.

Anyway, just before lunch yesterday, my application stopped updating the position of the terminal’s blinking cursor. You would think that a product named Curses could keep track of a cursor wouldn’t you?

Closer inspection revealed that all the keys worked properly, TAB cycled through fields as expected, and the Curses getyx() call reported that the cursor was in the correct place. Only the cursor wasn’t in the correct place at all; it was stuck half way down the screen, and it was blinking at me.

I spent the next 14 working hours debugging.

It came down to a function named getch(), which gets characters. I thought I was calling the standard ‘C’ library getch(), but it turns out I was calling a C++ member function named getch(). During a refactoring, I moved the getch() call from one class to another, and all of a sudden it was now referring to a global function named getch(). This global function worked fine, except for entirely screwing up cursor positioning.

In fact, the NCurses header files declare fifteen different getch()s. Some are global functions, some are member functions, and some are macros. I still can’t pin down exactly which one I was calling, but it was a one line fix.

And the moral is, “When you need to get a char, use the Curses getch(), without the cursed gotcha.”

By alang | # | Comments (1)
(Posted to Software Development)

Python and the Linux User Mode File System

9 PM December 11, 2003

The newly released LUFS-Python is a Python interface to the Linux Usermode File System, and it looks pretty neat.

Since I hadn’t even heard of LUFS, before, I went and installed1 it tonight, then used the provided ssh file system to connect to my web host. It all just works. I can edit my website’s files like they were on a local disk, though saves are a little slow.

Simon Willison and his readers have some neat ideas about what you could do with LUFS-Python, assuming the combination of LUFS and Python is stable enough.

Myself, I’d like to build a filesystem interface for CVS, mostly as an academic exercise.


1 Thanks to the Power Of Gentoo Linux, ‘installed’ is really too grand a word for the process. I simply typed ‘emerge -s lufs’ to search for a lufs ebuild – version 0.9.5 was available, and then ‘emerge lufs’ to download and compile it. A few minutes later, LUFS was up an running. Even less fuss than a typical Windows, “Next, Next, I Agree, Next, Next, Next” install.

By alang | # | Comments (1)
(Posted to Software Development and Python)

Elementary Latin for Mr Bush

5 AM December 11, 2003

Tedious Soporific points to a quote from an Economist article on Brad DeLong’s blog. The article gives President Bush a hard time for taking credit when perhaps credit is not due. I don’t think this is really fair – politicians constantly get the blame even when blame is obviously not due, so why shouldn’t they take credit when it might conceivably be due?

The article has more harsh words for President Bush:

Gary Clyde Hufbauer of the Institute for International Economics (IIE), a Washington think-tank, warns against the post hoc ergo propter hoc fallacy. That won’t bother Mr Bush, who is not known for his command of Latin….

I’d like to help out President Bush and everybody else who didn’t do enough high school Latin to translate “post hoc, ergo propter hoc”. Word by word, we have:

  • post* v. To send by mail.
  • hoc n. Illegally distilled alcohol – moonshine, rotgut.
  • ergo adv. Therefore.
  • propter n. Ancient Roman cross between a helicopter and propeller driven aircraft.

“Post hoc, ergo propter hoc” therefore means:

“Send moonshine by mail therefore the moon-shines on the auto-gyro”.

I can see the logical fallacy in that.

By alang | # | Comments (1)
(Posted to Rants)
© 2003-2006 Alan Green