What I’m reading lately: Greppability, Hebb’s dictum

A few good blog posts and things (by other people) that I’ve seen lately:

“How to fork” (Joaquim Rocha, September 2024) describes best practices for maintaining a long-term fork of an open-source project when the upstream is still fairly active. This is exactly the kind of thing I do with Clang/libc++ and VBCC — and Joaquim describes exactly how I do it.


“Greppability is an underrated code metric” (Moriz Buesing, August 2024) articulates one of my pet peeves. Moriz advises “Don’t split up identifiers,” as in:

string getTableName(const string& addressType) {
  return addressType + "_addresses";
}

or:

assert animal in ["leopard", "tiger", "zebra"]
filename = animal + ("spot" if animal == "leopard" else "stripe") + ".txt"

Instead, prefer:

string getTableName(const string& addressType) {
  return (addressType == "shipping") ? "shipping_addresses" :
         (addressType == "billing") ? "billing_addresses" :
         throw OopsError();
}

filename = {
  "leopard": "leopardspot.txt",
  "tiger": "tigerstripe.txt",
  "zebra": "zebrastripe.txt",
}[animal]

That way, someone grepping for “shipping_addresses” or “tigerstripe.txt” has a chance of finding the information they’re looking for.

To that I’d add “Don’t split up user-visible messages.” You have no idea how annoying it is to find the line of code that produces a message such as Error: too many connections to the foo database when that line is formatted like:

my::debug::print_error("too many "
    "connections to the foo "
    "database");

For the sanity of your maintainer (who may be your future self), I recommend never linebreaking in the middle of any string, with the possible exception of before or after an escape sequence like \n for which you wouldn’t expect anybody ever to grep.


“Higher-order truths about chmess” (Daniel Dennett, 2006) is a good cold dousing thrown in the direction of some pedantic pursuits. I certainly resemble its target, sometimes. Dennett writes:

Some philosophical research projects are rather like working out the truths of chess. A set of mutually agreed-upon rules are presupposed, and the implications of those rules are worked out, articulated, debated, refined. So far, so good. Chess is a deep and important human artifact, about which much of value has been written. But some philosophical research projects are more like working out the truths of chmess. Chmess is just like chess except that the king can move two squares in any direction, not one. […] There are just as many a priori truths of chmess as there are of chess (an infinity), and they are just as hard to discover.

But (and this is the point) to devote oneself to the deep study of chmess, to contribute to its scholarly apparatus, is fundamentally a complete waste of time and energy.

One good test to make sure you’re not just exploring the higher-order truths of chmess is to see if people aside from philosophers actually play the game. […]

As Burton Dreben used to say, “Philosophy is garbage, but the history of garbage is scholarship.” Some garbage is more important than other garbage, however, and it’s hard to decide which of it is worthy of scholarship.

Dennett quotes Donald Hebb, who said (somewhere, allegedly):

If it isn’t worth doing, it isn’t worth doing well.

That is, you shouldn’t spend your energy on doing well that which oughtn’t to be done at all. And conversely, perhaps, it should not surprise us when a needless task is also performed poorly.


Appropriately for both this Columbus Day weekend and my currently running book club on Ovid’s Metamorphoses, I devoured Richard Armour’s ersatz history of Europe, It All Started with Europa. Armour (1906–1989) was both a professor and a prolific humorist. He used to say he had two costumes — cap and gown and cap and bells.

“If a thing is worth doing at all,” said Ivan IV, “it is worth doing terribly.”

Catherine the Great frequently entertained literary personages such as Diderot, who complimented her on her mind, a part of her which had been overlooked by most of her friends.

Some say that Catherine corresponded with Voltaire, but actually the similarity was slight.

Posted 2024-10-15