Saturday, February 20, 2010

Control-key behavior for non-Qwerty layouts

I type with Dvorak, but I keep a Qwerty layout installed for when other people need to type on my computer. Normally this works well, but the one holdout is gnome-terminal. Today I found out that it's not a bug, but a feature:

https://bugs.launchpad.net/ubuntu/+source/gnome-terminal/+bug/204202

What happens is that gnome-terminal, knowing better than I do what keyboard layout I would like to be using, switches back to the system default layout whenever control is pressed. When I press control-D, it switches me to Qwerty and generates control-S. There's no option. It insists on helping me no matter how much I would rather it didn't.

This was a really disappointing thing to learn. The situation is wrong on multiple levels:

  • There is already an elaborate system in place to handle issues like this: the X keyboard layout, which maps keycodes to keysyms. It's the approach taken on Windows and Macs to this problem, and it works fine for X, too. Despite the existing solution, Gnome invents their own kludge that reinterprets what the layout layer already decided.
  • There is no option for this behavior. It's pure "do what I mean", and if it guesses wrong, you're only recourse is not to use the app at all.
  • There is a long list of complaining users on the bug log, and they are met by being told their use case is outnumbered so go away. This is not a good reaction to people who have totally normal setups that worked in previous versions of the system.
  • No other apps do this annoying remap. Thus, even if I wanted it to happen, I would only get it in gnome-terminal. Thus, it doesn't even solve the problem for people who like this layout. People who like it still need to change their keyboard layout, anyway.

As far as I can tell, the solution that will be adopted is to adjust the heuristic. Count me underwhelmed. The whole feature should be scrapped, but instead it's being further refined. In short, I agree with Simon Kagedal's conclusion:

Personally I feel that the way (I think) Windows works would be the best, i.e. that the keymaps themselves contain the correct information on how modifiers should work...

Wednesday, February 17, 2010

Computer Engineer Barbie

From gizmodo:

This is actually wonderful. Barbie's had 124 careers since 1959, ranging from Stewardess to Paratrooper. Today she gets her 125th: computer engineer. You can tell she's smart 'cause she's got glasses, and reads nothing but binary.


I like the bluetooth headset.

Saturday, January 30, 2010

They r true hero's

Ludacris writes:
These are the doctors who took my plane down 2 Haiti to deliver supplies & just landed.They r true hero's

Check out the linked photo. The two on the left have been working in a medical field clinic in Haiti. The one on the right is Kathryn Bolles, a friend of Fay's since childhood, who works for Save the Children.

Ludacris is telling the troof. These three have hardly slept since the earthquake struck.

Monday, January 18, 2010

Food science

Food science is the best kind. Check out John Weathers' double-blind test of.... Earl Gray teas. You don't need a lab coat to be a scientist. Study something you love and try to find out the truth.

Wednesday, December 30, 2009

Run-time types

Guy Steele ruminated a few weeks ago about run-time types:

When Bill Joy and I were working on The Java Language Specification 14 years ago, we wrestled with the distinction between "types" and what many people were calling "run-time types". We found that the the term "run-time types" was causing some confusion, in part because some people seemed to think (a) that an object could have a compile-time type as well as a run-time type, and/or (b) a variable could have a run-time type as well as a compile-time type, and/or (c) that any type could serve as either a compile-time type or a run-time type. In the end, we tried to abolish the term "run-time type" in Java by abolishing it in the language specification.


This issue is coming up for the GWT compiler as we enrich the type hierarchy used within the compiler, only worse. Not only are there types in the source language that differ from the types available at run time, but there is a third type hierarchy used internally by the compiler. How do we make sense of all these type systems?

Steele and Joy have tried to eliminate the very notion of run-time types. However, as the post above indicates, they still haven't found a satisfactory replacement for it. One attempt is to use "class" instead of "run-time type", but how are we supposed to think about the run-time type of an array? Worse, what can GWT do, when it has not two but three type systems of interest? Steele wants a second word to replace "run-time type". GWT would need a third word.

With some trepidation, let me defend why I think run-time types are a useful concept. I have a feeling I am wandering into a quagmire, given the unease of others who have tried it, but so far I don't see exactly where the problem is. I'll give two motivations, and then I'll give some specific details on how I think of the type systems relating to each other.

The first reason to have run-time types is that it's the most obvious thing to call them. Java has a stark distinction between the types in the source language and the types you can test at run time. Thus, there are two systems of type-like things involved. At the same time, both systems are very type-like. They have a subtyping hierarchy, and they have a inclusion relation where some values are in the type and others are not. Thus, we are talking about type-like things that only exist at run time. It's simple English to call these things run-time types.

The second reason is that it works out well in formal language semantics. In Igarashi and Pierce's paper describing the erasure model for compiling Java, you start with a program using source-level types and "erase" parts of the program. For example, type List<String> becomes simply List; the String part is erased. After erasure, you still have a well-typed program. There's nothing special about it. The type system used for the new program is different than the type system for the old program, but it's still a type system in every way. Thus, run-time types appear to be well founded theoretically.

Based on motivations like these, I like to think of run-time types as a first-class concept. More generally, I think of all three of the type systems the GWT compiler sees as plain old type systems.

The trick, then, is how to think of the relations between these type systems. First of all, the GWT compiler largely ignores the Java source-level types. Those are modeled faithfully, and they are available during user-supplied code generation. However, as soon as all code has been loaded or generated, the types are erased, just like in a Java compiler that targets bytecode. Thus, the bulk of the compiler doesn't even see source-level types.

More interesting is the interpretation of the compiler's internal type system. I think of it as supplying extra information that the compiler knows to be true. For example, the internal type system has a "null type" that isn't available in either the source language's type system or the run-time type system. Whenever the compiler can prove that an expression will always evaluate to null, it can replace that expression's type with the null type. Whenever the compiler sees an expression of type null, it can use that for further optimization. For example, if it sees "foo == null ? a : b", and the type of "foo" is the null type, it can drop the "b" and replace it by "foo; a". It knows that "foo==null" will always be true.

The main mind-bender I have encountered with this approach has to do with the fact that compiler types can't be fully checked at run time. What is the meaning of a cast expression where the target type is something that won't be checked at run time? How should it be compiled? Should we feel compelled to add extra run-time checks corresponding to the enriched internal type system?

My current answer is to simply avoid the whole question. It's presently an invariant of the GWT compiler that every cast expression and every instanceof check tests against a run-time type. Problem solved. This approach is a cruder version of the "dcast" predicate used in Igarashi and Pierce. Looking forward, it would also be possible to add a second kind of cast operation, one that the compiler has proven will always succeed. Such a cast can cast to an arbitrary internal type, because it won't be emitted into the final output. So far, though, such a cast hasn't been strictly necessary.

Overall, run-time types look not only useful, but well founded and intuitive. They're types, and they're present at run time.

Tuesday, December 29, 2009

Browsers giving up on repeatedly failing script tags

Today's browser oddity is that Chrome instantly fails a script tag download if the requested URL has already failed a couple of times. It stops issuing network requests and fails the download before even trying. Probably other WebKit-based browsers do the same; I didn't check.

I can see why this behavior would make sense if you think of script tags as part of the static content of a page. If there are ten script tags requesting the same resource, you don't want to issue ten failing requests. However, it caught me by surprise, because I'm trying to use script tags as a way of downloading content over the web.

Browsers sure are a messy platform.

Wednesday, December 23, 2009

More software patent extortion

"Microsoft lost a patent case involving a company called I4i in May, after a jury ruled that Microsoft infringed one of i4i's patents with a custom XML feature found in Word. In August an injunction was placed on sales of Word pending the appeal, which did not go in Microsoft's favor Tuesday."
- from CNET

Sad news. Patent 5,787,449 has been upheld.

On the one hand, Microsoft deserves what it gets for supporting software patents. On the other, the patent system is just terrible. Not only does this patent cover boring and well-known techniques, it was actually upheld in court.