2005-01-08

Insolent bc(1)

I read Jonathan 'Wolf' Rentzsch's recommendation of Longhand with interest because I'm in a similar situation. I've used many calculators (both physical and virtual) in my time, but I still haven't found the one I'm completely happy with.

I have a Calculator window open right now; a testament to the fact that if your job is sufficiently simple, Calculator doesn't totally suck. Anyone who thinks that an on-screen imitation of a physical device is a good idea just isn't thinking very hard. The problems with Calculator and DVD Player, two of Apple's worst interfaces, boil down to this mistake. (Actually, the unnecessary power given to DVD creators handicaps anyone wanting to make a really good DVD interface, because there's a lot of room for bad interface on the DVD itself. The truly insolent "NOT PERMITTED", and the messing about on the "loading screen" before you can get the damn thing to play. There's a level of hell reserved for those idiots.)

But back to calculating...

Under no circumstances would I even consider using AppleScript. It still strikes me as a theoretical exercise in constructing Perl's dual. If you've ever wondered what a read-only language would look like, AppleScript is it. The sooner that revenant from the ancien regime goes to its grave, the better.

I do use bc(1), though, especially for base conversion. I use it less now that Terminator lets me simply select any number (or copy it to the clipboard if it's in a different application) and see it in whichever of decimal, hex, octal, and binary it wasn't already in. That's a really cool feature, and it's given me a new pet peeve of waiting while someone converts bases in their head or with some other tool, rather than just double-clicking. It's almost as annoying as those people who scroll up and down looking for something rather than use find.

I hate bc(1) too, but mainly because scale has a stupid default (so 22/7 gives 3). There's also the fact that it's Yet Another Language I Don't Use Often Enough To Remember. The command-line tool underlying Longhand seems (based on my superficial examination) to be pretty similar, but I'm hopeful that the GUI (which I haven't seen yet) might try to make the functionality less invisible.

Jon has two problems with bc(1). He says:

(Why do I hate bc? Two reasons: the dumb ABSOLUTELY NO WARRANTY banner it prints upon launch and the fact it catches control-c and tells you to type quit to exit. Either exit should exit, or it should honor my control-c (or both). Usually I simply close the entire Terminal window. I actually derive pleasure from force-killing bc that way. Die insolent software!)

I'm ambivalent about the banner. I can see both sides' point of view. Yes, it's ugly; yes, it might save the authors some grief they don't want. Using the -q argument, or setting BC_ENV_ARGS to -q suppresses this anyway.

I find his control-C complaint odd, though, as someone from a Unix background. I'd use control-C if I wanted to interrupt bc(1), but not if I wanted to quit. It's an interactive program, so I'd use control-D to signal the end of input, and it would go quietly into the night. bc(1) might be "insolent" in refusing to die when interrupted, but it's rude to interrupt in the first place!

What about "quit" versus "exit"? True, some programs understand both. ftp(1) is an example. But a lot only understand "quit". gdb(1) is probably the one I use most often:

hydrogen:~$ gdb
GNU gdb 5.3-20030128 (Apple version gdb-330.1) (Fri Jul 16 21:42:28 GMT 2004)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin".
(gdb) exit
Undefined command: "exit". Try "help".
(gdb) quit
hydrogen:~$

(Hey, look: it has an ugly banner too!)

I can't think where the argument comes from, but the argument I'm familiar with for why Unix programs should only understand "quit" is that "exit" is for the shell. The shell understands "logout", too, but "exit" is more common, perhaps because of its use in shell scripts.

More common still is the use of control-D. Which works for all interactive programs not just the shell. So is it worth trying to reserve "exit" for the shell? Probably not. But who'd type any of these when they can just hit control-D anyway?

Actually, my other personality – the one who uses gdb(1) – reminds me that we always quit gdb(1) with "quit". Neither of us knows why. Perhaps it's something to do with how heavyweight the program feels? bc(1) does its best to come across as a filter (albeit one with an ugly banner) waiting for the end of input, whereas gdb(1) really does come across as an interactive program. One worthy of a "quit".