Wandering Thoughts archives

2008-05-30

The fun of awk

I like awk, I really do, but sometimes it really irritates me. Take, for example, this fun little awk program:

awk 'BEGIN {print "5" == "05"}' /dev/null

You might rationally expect this to print '1' (awk's boolean truth value). As I found out once, you would be sadly mistaken; this is false, presumably because awk winds up doing a string comparison instead of a numeric one. Too bad if you're reading one set of fields that are zero-padded and one set that aren't.

(The workaround is add 0 to the "05" to force the numeric interpretation; "5" == ("05"+0) comes out true.)

This shows two drawbacks of the sort of magical conversion between numbers and strings that awk does. First, this sort of stuff involves heuristics, and heuristics are inevitably wrong sooner or later. And second, if you do not have the fine details carefully memorized you can wind up surprised.

At the same time such magical conversions live on because they are oh so very handy when you are banging things in a hurry. Considering the sorts of things that awk was designed for, this is completely the right decision for it; having to write explicit Python-style conversions all the time would probably drive me up the wall, however much I like them in Python.

programming/AwkFunWithEquality written at 23:25:47; Add Comment

Users are rational

Here is something important to remember about your users:

Users are rational.

Users aren't crazy, and they don't do things just to irritate you; what they do and what they report about problems is not crazy from their perspective, however odd it looks from yours. If users report 'I cannot log into the intranet' when they cannot log in to the IMAP server, it is not because they are stupid, it is because 'the intranet' is how they think about your system.

(The answer to 'how can they be so ignorant?' is that they don't care to learn the details, any more than most people care to learn the details about how their phone service, their plumbing, or their car work. Everyone has massive areas of ignorance in their life; it's how we deal with a very complicated world.)

I think that it is especially easy for system administrators to fall into this mindset, because we see our systems so clearly that we can easily miss how other people don't and how complicated things are from an outside perspective and so on. (Plus, there is a cultural tradition of sysadmins thinking of their users as stupid, however ill advised this is, with all sorts of supporting cultural institutions and mythology.)

One of the corollaries of this is that how users refer to things gives you valuable clues about their mental model of your systems. This is not just useful for understanding problem reports and requests; it's very important for building systems that behave predictably and do what the users want, and making sure that the users have an accurate mental model of what is going on is vital in avoiding terrible mistakes.

(This is closely related to how users are almost always right.)

tech/UsersAreRational written at 00:23:43; Add Comment

By day for May 2008: 1 2 3 4 5 6 7 8 9 11 12 13 15 17 18 19 20 21 23 24 25 26 28 29 30 31; before May; after May.

Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.