November 30th, 2004

  • evan

shadowing fun

I've mentioned this quirk before, but I still find it amusing: variable initializations in C can refer the the variable itself. In other words, every let works like a letrec.

So I can do stuff like:
char *crazy = malloc(strlen(crazy) + 1); /* make crazy exactly as big as it ought to be. */

This has the effect that you can't shadow a variable with a variable defined in terms of the shadowee.
Code like this:
int t = 0;
int t = t + 1;
printf("t %d\n", t);

Doesn't print out 1 unless you're lucky. While this seems like a crazy thing to do, I find it's a pretty common idiom in ML (where you don't need to create a nested scope to shadow) for when you're functionally updating something.

A C analogy might be something like, for example,
p = sprintf(buf, [...]);
p = sprintf(p, [...]);
p = sprintf(p, [...]);

where mutating p isn't really the goal.
  • evan

translating file names

On a GNOME list they're discussing directory names. On a translated system, everything appears in your native language, until you open a file browser and discover your home directory is filled with directories named "Pictures", "Desktop", etc. What to do?
  1. Always create the directories with canonical, English names, and translate the names only when you display them in the GUI.

    Cons: GNOME apps will show one set of names for things, and Firefox, KDE apps, etc. will show another. Even GNOME apps that forget to canonicalize directory names will confuse users. Confuses terminal navigation because the names are wrong. What would typing in paths in a file chooser do--use the English path names or the translated ones?
  2. Or, when you create these directories the first time, translate the directory names depending on the user's language.

    Cons: screws up if the user switches languages. Screws up access via SSH if your terminal client doesn't support Unicode and your directory names are in Chinese. Screws up terminal navigation if the directory names are difficult to type. Screws up any program that doesn't understand Unicode filenames. Screws up any program's compile-time paths to files (though this could be addressed by an API that maps /home/luser/Desktop to /home/luser/Esktop-day).

Both sound pretty bad. For what it's worth OS X chose the former. Does anybody know what Windows did?

I remember discussing this with Brad for LJ's URL formats: we (I originally wrote he, but I didn't want to get it wrong and blame something on him; but I'm pretty sure it should be "he") wanted to not use English paths in user URLs, so (for example) the "archives" of the journal are just stored in date-numbered directories. Of course, you can't use Unicode in paths and there's still stuff like "friends", "?mode=reply", so you can't really win...