Saturday, September 20, 2008

Scientists and Engineers

I've been described, on occasion, as a computer scientist. This is incorrect: I'm not a scientist, I'm an engineer.

Not only is my degree in Engineering, not Science: I'm an engineer to the core, because I am thrilled by making things that are useful far more than I am about discovering truths about Nature -- the latter is fine, don't get me wrong!, a wonderful pursuit, and indispensable to keep pushing our civilization forwards in the long run, but -- as my own personal pursuit, it doesn't get my heart pulsing faster, make me sit upright, make my eyes shine, anywhere as much as the making of useful things does.

I would say I'm kind of a typical engineer: just like, say, Leonardo da Vinci, Ludwig Wittgenstein, Antoine de Saint-Exupery (he couldn't actually get his engineering degree, but, he tried!), Rowan Atkinson (of "Mr Bean"'s fame), ...

Tuesday, September 9, 2008

Python tips: the right way to show errors

I've lost count of how many times I've seen Python code like this...:

logging.error("Unknown user '%s' for '%s'"
% (username, resourcename))

This error-showing code has two problems:

  1. logging.error and other such functions do the formatting for you -- so don't duplicate their work! So, the first level of fixing is to change the call into:

    logging.error("Unknown user '%s' for '%s'",
    username, resourcename)

  2. any time you're displaying a string that's somehow "in error" (not just in calls to logging functions, but also when instantiating an exception, etc), use %r, not %s! This way, if the problem is that the string contains "invisible" characters, you'll see them clearly displayed as escape sequences, while %s might hide those characters, making debugging much harder. So, the second (and final;-) level of fixing is to further change the call into:

    logging.error("Unknown user %r for %r",
    username, resourcename)

Monday, September 8, 2008

Upper-class vs Lower/Middle-class English

I'm watching Branagh's "Henry V" with my wife, and (after I expressed my absolute awe at Emma Thomson's acting skill... all actors in that movie are good, Thomson upstages them all - she's AWESOME!) we stopped midway through (getting too late) and briefly discussed the play's famous structure. After the obvious notice of the alternation between "upper class" scenes (featuring kings, princes and dukes) and the "lower/middle class" ones (with corporals and, at best, lieutenants), I idly remarked how much easier it was for me (a foreigner who studied English as a second or third language -- it's debatable whether I studied more English, or French!) to follow the dialogue in the "upper-class" parts, than the others...

Well, guess what: Anna's exactly the other way 'round -- SHE follows the "lower or middle class" dialogue much better than the higher-class one! She, of course, is Minnesota (heart of the Midwest) born and bred... MY English comes mostly through Milton, Swift, Sterne, Smith, Franklin, Poe, Melville, Hardy, Shaw, Conrad, &c... HERS, though she IS uncommonly well-read for an American, comes mostly through the organic, word-of-mouth, generation-to-generation "normal" process of language transmission...

...and, it appears, the subset of English best transmitted by highbrow "culture" (e.g. to foreign-born students like me) is QUITE different from that which best survives through "natural" means (to native-born speakers) -- and the "class distinction" is just what one would expect! Reminds me of the way Latin came into Italian through two similarly separate channels: the spoken-word natural one (which e.g. made gold into "oro", laurel into "alloro", &c) AND the "high culture" mostly-written one (which gives us such words as "aureo", golden, and "laurea", the university degree traditionally celebrated with laurel crowns).

The change of classic high-class diphthong "AU" into common-speech "O" is well attested even in late-Republic Rome -- e.g. the member of the ancient Claudius family who went for unstinting populism signaled that by changing his name to Clodius!-) -- so that's a particularly good example;-). However, this general kind of distinction (between high-culture, mostly-written transmission of language, and normal-people, mostly-spoken one) is VERY common in all languages, and English, this most wonderful and most mongrel of languages, is no exception;-).

Sunday, September 7, 2008

The Pedant Reigns

Robert Reich is always worth reading, content-wise... but I'd have to unsubscribe from his blog if I couldn't lower my blood pressure by venting when he slaughters the beautiful English language! In his latest post, he (rightly, content-wise) reminds the reader how the GSEs "blocked any attempt to reign in the risks". Robert, it's REIN IN, not REIGN IN.

Reins (no G in it) are what you control a horse with, and by analogy they're used to indicate such control (as in the idiom you mis-used); it comes from Vulgar Latin "RETINA", constraint, from "RETINERE", to constrain (from "re-tinere", literally "to hold again"); close cognates in English include "retain" and "retinue".

A reign (with a G) is the period during which a certain monarch is on the throne, that monarch's authority and dominion, his or her rule; it comes from Latin "REGNUM", kingdom or reign, related to "REGULARE", ``to rule''; deep down, it coms from Proto-Indo-European root *reg-, just like your own surname, and a wide variety of words such as "right", "rich", "Raja", "rector", "erect", "royal", "realm", "rule", ... which got into English through many different routes.

It IS unfortunate that these unrelated words, rein and reign, ended up in English with the same pronunciation, very similar spelling, and even vaguely cognate meanings...!-). But PLEASE think of their differences, and let your readers focus on the very important and relevant messages you're sending (in this latest blog, about the horrors of the GSEs, Fanny and Freddie, based on private profits but socialized losses), rather than risk apoplexy over your usage of English... THANKS!

Saturday, September 6, 2008

PIL on Mac OS X 10.5 with Google App Engine

I have recently opened a couple of issues on the Google App Engine tracker: 685 about installing PIL on Mac OS X 10.5, which is harder than GAE's docs make it out to be, and 695 about actually getting it to work with the wonderful GoogleAppEngineLauncher (so you can run locally GAE apps that use the images API), which requires some trick. So I just thought it might be useful to somebody else who uses Mac OS 10.5 and GAE if I summarized the necessary steps and workarounds.

GAE docs claim that "Installing PIL on Mac OS X 10.4 and 10.5 can be completed in a few simple steps", but if you just follow the steps they suggest, on 10.5, the PIL installer will refuse to install -- the installer was written for 10.4 and it does not recognize the "stock" Python that comes with the OS for 10.5. As Matt Kangas has posted, before you run the PIL installer, you need to make a symlink:

cd /Library/Frameworks
sudo ln -s /System/Library/Frameworks/Python.framework/ Python.framework

He also suggests placing in your .bashrc

export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/

The latter environment variable (I placed it in .profile) is indeed sufficient to let you use PIL from a Terminal session, including one in which you run from the symlink that GAE installation places (if you allow it to) in /usr/local/bin. However...

Once you've done all of this, the GoogleAppEngineLauncher still won't let you use PIL (and, therefore, it will disable the images API in the GAE apps it runs locally), because it doesn't know about your .bashrc or .profile! You need to find another way to extend Python sys.path's appropriately. The simplest way is to make a file named PIL.pth with a single-line content:


and place that PIL.pth in any of the directories that all Python processes see; in my case, I used /Library/Python/2.5/site-packages/ -- but that directory is not available in a pristine installation of Mac OS X 10.5 so you may have to use some other directory.

This post is (I hope!) only of temporary usefulness, as it will be superseded when the PIL installer is rebuilt to properly support Mac OS X 10.5 (or, if that installer is never rebuilt, this post can still be made obsolete by the tiniest fix to GAE and its docs to close the issues I've mentioned above!), but, in the meantime, HTH!

Tuesday, September 2, 2008

The Pedant Awakes

Some are born pedants, some achieve pedantry, and some have pedantry thrust upon 'em.

I'm in the first category. I can't help it: malapropisms LEAP to my eyes, raise my blood pressure, make me feel PAIN. I've long mused that I should start a blog to vent about these painful attacks against my sanity -- the it's/its'/its horrors, the there/they're ones, "reign in" to mean "rein in", "baited breath" for "bated breath".... and so on, and so forth... venting would lessen the pain a little bit, maybe lower the ol' blood pressure a tad, too. But, round tuits tend to be in short supply.

Today's the day the Pedant awakes from his slumbers and SHOUTS -- "I'M MAD AS HELL, AND I'M NOT GOING TO TAKE IT ANY MORE". Watch out -- the Pedant awakes, the Pedant is coming!

Google Reader "share with friends" is a delightful little touch... and today my wife "shared" a generally excellent post by Garr at Presentation Zen, so of course I read that... I enjoy Garr's blog and his excellent book, and anything my wife thinks is worth sharing deserves attention.

Midway through... "Fast/slow, loud/quite" -- OUCH. I take a deep breath or three -- come on, that's no malapropism, it's a perfectly normal typo, swapping the final E and T... they can happen to anybody, they happen to me, too. Calm down. Resume reading. But, towards the end... "his son Michael Reagan eluded to today". AAAARGH!!! I stormed upstairs to my wife, shouting, DEMANDING to know WHY, OH WHY, she would ever share a post using "eluded" to mean "alluded" -- it's not as if my life insurance was juicy enough to make her WANT to cause me to have a heart attack, after all... so what WAS her motivation?!

Turns out... she didn't even notice. When the general disrespect and spite for proper usage has become SO bad to numb even Anna -- whom I love, among innumerable other reasons, for being quite a match for me as a pedant and copy-writer supreme -- when SHE fails to notice something as horrible as THAT, well... then it's HIGH TIME for the Pedant to Awake, and Stride the Blogosphere ranting and venting and whining.

So *WATCH OUT* from now on, especially if you write generally interesting and worthwhile prose, whether you actually MEAN "insure" or "ensure" (or maybe "assure"...?!), whether you're REALLY trying to speak about the "File Transfer Protocol protocol" ("FTP protocol" occurs hundreds of thousands of times on the web...) or the "North-Atlantic Treaty Organization organization" ("NATO organization" has over ten thousands hits), whether you mean "except" or "expect", and so forth... if you slip, the horrible price to pay just MIGHT be... *a mention on this blog*!!!