Hazards of Best Practices

“Best practices are a hazard because they ask us to substitute slogans for thinking.” — Pete McBreen, p. 125 Software Craftmanship.

Sometimes best practices are used to shift blame by using the bandwagon fallacy: “Everyone else is doing it — it’s a best practice, so don’t blame me”. Sure, there’s strength in numbers, but not necessarily wisdom in numbers.

ORM Solutions for C++ and sqlite: hiberlite, SOCI

I think SQLite is a great database for a C/C++ application to use. It sure is easy to query the data that way, without intrinsic support from the application. When the application changes, the database is still accessible via standard sqlite clients. Yet using SQLite in an application can require a lot of repetitive code to serialize objects to and from the database, so I wondered if there are ORM solutions for C/C++. It turns out that there are. I only had to turn to stackoverflow.com to find the following (among many):

  1. Hiberlite
  2. SOCI

NPR: When Patents Attack!

I write software for a living, and I have a hard time recognizing redeeming value of software patents (other than to have something to negotiate with when someone tries to sue a company). Reading the NPR transcript about patents got my blood boiling. The system has been gamed, and patent troll companies legally extort money from other companies.

Read or listen here. Are there good reasons to have software patents, and if so, on what types of inventions and in what circumstances?

Norton 360: Unbearably slow

I’ve got a Windows Vista laptop that’s about five years old. It’s a dual CPU machine with 2G of RAM. After installing several bits of new software, I noticed that it was unbearably slow when logging in, switching users, and logging out. The CPU use wasn’t too high, but the disk drive light indicated that it was being kept very busy. I booted Fedora 14 Live from a USB drive, and the computer was snappy and responsive.

I monitored the system processes, and most of the I/O reads and writes were attributed to svchost. On a Linux or UNIX machine, it would have been easy to identify which service was the culprit because each service (known as a daemon) runs as a separate process. But in Windows, services run as part of svchost, making them hard to identify and monitor individually.

Since I didn’t know what was causing the slowness, I guessed and uninstalled Mozy backup. Nope. That wasn’t it. My computer was still slow. So I uninstalled Norton 360. Problem solved. The computer is responsive and snappy again, and has remained so for the past month.

Shortly after I uninstalled Norton 360, a neighbour called and asked if I could figure out why “the Internet was running so slowly”. He thought he had Windows 7. When I arrived, I found that it was Windows XP running in 512M of RAM. I booted Fedora 14 from my USB flash drive, and found that his computer ran quickly and loaded web pages quickly. His Windows XP machine was running Norton 360, and task manager showed that Norton processes were consuming large amounts of disk I/O.

I uninstalled Norton 360, and on the recommendation of a smart colleague, installed the free Microsoft Security Essentials. The computer ran quickly after that. My neighbour is pleased. I went home and installed Security Essentials on my Vista machine, with little noticeable slowdown.

My conclusion is that Norton 360 may only be appropriate for newer hardware and generous amounts of RAM (4G or more).

Gnome 3: Not quite ready for prime time

Just over a week ago, I installed Fedora 15. After using Gnome 3 for two days, I decided that I’m better off using Gnome 2, KDE or XFCE.

With Gnome 3, I like the ability to type the name of the application I want to run instead of hunting for it in a menu. This is a feature I’ve enjoyed for the past five years with Windows Vista, so it’s refreshing to finally have it appear in Gnome.

With Gnome 3, however, I miss the following:

  1. A system monitor applet. When my system starts to feel slow, I pay attention to CPU and I/O wait overhead.
  2. Multi-monitor support when changing workspaces. When I move to a new workspace, Gnome 3 only moves one of my two screens to a new workspace. The other stays the same.
  3. Quick launch icons. I use them for Firefox, gVim, Eclipse, and other frequently used apps.

I expect that Gnome 3 will be improved rapidly, and Fedora 16’s Gnome 3 will more productive.

Update: There’s a list of ways to tweak Gnome shell to make it almost bearable: http://forums.fedoraforum.org/showthread.php?t=263006. In particular, by installing and using “gnome-tweak-tool”.

Misc Linux things: PATA or SATA, mutt and mailcap, tarsnap backup

The other day, I wondered whether the drive in my laptop was PATA or SATA. Fortunately, I didn’t have to tear it apart to find out. I simply wandered over to stackexchange.com and asked the question. Here’s the answer:

lspci -d $(cat /sys/block/sda/device/../../../vendor):$(cat /sys/block/sda/device/../../../device)
readlink -f /sys/block/sda/device/../../../driver

I’m a long time user of the mutt email client (as well as Thunderbird). At some point, viewing the HTML attachment (with the ‘v’ key) stopped invoking ‘lynx’ via my mailcap file. It turns out that the developers of mutt added an internal viewer, and moved mailcap support to the “m” key. I took the time to switch from using ‘lynx’ to using ‘links’. Here’s the entry from my $HOME/.mailcap file:

text/html; /usr/bin/links -dump -force-html %s; copiousoutput; nametemplate=%s.html

I’ve been gradually looking for an online, off-site Linux backup tool for  the past few years. I tried spideroak, but wasn’t pleased with the giant log files it kept in my home directory, and it wasn’t designed to back up files outside of my user account. Lately, I stumbled on another promising tool: tarsnap. I haven’t tried it yet, but I will. Pricing looks reasonable, and since it “deduplicates” storage, it means that I shouldn’t be backing up the same thing repeatedly. Here’s how one person configures tarsnap to keep up to X daily backups, Y weekly, and Z monthly.

Fedora 14, SSH ports and SELinux

SELinux in Fedora 14 is configured to constrain the ports on which SSH can listen (see the bug report). The solution:

setsebool -P sshd_forward_ports 1

This allows SSH to listen on ports besides 22, and to forward ports. Reading the bug report is interesting. In my opinion, OpenSSH has an outstanding security track record, and we probably don’t need additional SELinux policy to constrain it. It’s probably wise to practice security in-depth (to have more than one line of defense), but it creates a large road bump for most SSH power users. From what I read, it sounds like most people still disable SELinux.

Teriffic Linux Books

One of my QA coworkers had The Linux Phrasebook sitting on his desk. I noticed it was by Scott Granneman, and immediately thought, “if it’s by him, it’s got to be good.” As I thumbed through the pages of the book, I was impressed at the practical coverage of command line utilities including yum and rpm, apt and deb, etc. I highly recommend this book. It’s small so it’s easy to keep on hand.

For anyone wishing to write applications that take advantage of all that Linux has to offer, I recommend The Linux Programming Interface (also available from Amazon), aka TLPI. I used to recommend Stevens’ Advanced Programming in the UNIX Environment, but now I recommend TLPI because it is more comprehensive and just as readable. It’s not a small book, so a PDF makes it easier to keep on hand. I purchased my copy through the publisher, NoStarch with the coupon code “Mamaku” that gave me 30% off and a free PDF. The order total came to $80.00, including shipping.

Awesome Linux profiling tools: top -H and pstack

When I needed to figure out where the performance bottlenecks were in some Linux software, I found helpful answers at http://stackoverflow.com in the form of two tools: 1. naming threads in combination with “top -Hp <pid>” and 2. “pstack <pid>”. The first was helpful in watching which threads were consuming the most CPU. The second was useful in sampling the application over time to find the hot spots and their stack traces.

  • How to name a thread in Linux (or a process) — use prctl().
  • How to use stack sampling to find performance problems — use pstack.