2007-10-31 22:53Control + Backspace (and the Object-Oriented Programming joke)Having looked in my Mystery Box of potential topics for blog posts, I’ve found a couple of things which are relatively short and don’t really make sense on their own. The first is an observation about key combinations on the command line, and the second is a joke which came to me recently and I wanted to publish before someone else came up with it independently. By my calculations, the first half of the post will be technical enough to justify writing this, and the second half will be funny enough to justify someone reading this, but not by much. Control + BackspaceAs UNIX gurus will know, the default key combination to remove the previous word on the command line is “Ctrl+W”. The thinking behind that is apparently that “W” stands for “word”, and presumably “Ctrl” stands for “Delete, except all the other times when it means something else”. As man bash so eloquently puts it:
Unfortunately this particular key combination is quite popular for other, more drastic functions, in applications which use the standard Ctrl+Delete combination for deleting a word and thus have Ctrl+W free for other things. In Firefox for instance, Ctrl+W is “Close Tab”, as it is in at least two IRC clients. This is what triggered the following conversation (well, “rant” on my part) in IRC (names changed to protect the innocent): ← foo has left this channel (Leaving). → foo has joined this channel (foo@example.com). <foo> yes, xchat <foo> once again, when I type ‘Ctrl-w’, that’s _not_ what I mean <bar> teehee <Hagfish> BazChat problem too. <Hagfish> Well, it’s not their problem, they behave correctly, it’s bash that’s the problem. <Hagfish> Well, technically readline. <Hagfish> Well, technically the terminal emulator not being able to send Ctrl+backspace key sequence. <Hagfish> But that’s fixed in KDE4. <Hagfish> So next year, the command line will just become a complex, bad usability interface to powerful programs. <Hagfish> I look forward to it. <Hagfish> Now excuse me, I’m going to go drag and drop something. My KDE4 comments relate to the fact that you can configure readline and thus BASH to accept Ctrl+Backspace as the “delete word” key combination, but Konsole is incapable of sending a unique byte sequence for this combination without some serious configuration file hacking. That’s not to say it is impossible, just ludicrously unrealistic to expect of a novice user — the sort of person who would be most fazed by emacs-style editing commands in the first place. Despite this, there is a valiant attempt at making an easy to understand set of instructions for changing from Konsole’s defaults, but they could be dramatically reduced in length and complexity if KDE bug 84457 was fixed, or rather if KDE4 was released, which contains a version of Konsole that contains the fix. The Object-Oriented Programming jokeAll right, here’s the bit you’ve been waiting for, but don’t set your hopes too high: A member of the public walks into a method of an inner class, and the interpreter says “You can’t come in here! This is a private function!” Just to remove any semblance of comedy that might have made it into that joke, I will analyse it to death, explaining why it is technically accurate (in case you are unfamiliar with OOP) and how the idea for it came into my head (in case you are unfamiliar with inspiration). Firstly, in OOP, you have things called “classes” which can contain other classes, and the inner classes are effectively “private” in that they cannot be accessed by things other than their containing class. Then there is the fact that a “method” is a function that an object can perform, and an object is a concrete instance of a class. Finally, in OOP languages you can declare things to be “public” and they can have “members”, so those words were chosen deliberately. So how did I come up with this crazy idea for a joke? Actually, the question I’m asking myself is why did no one else come up with it first (I have done a quick web search for it)? Anyway, I was writing some OOP code and there was a particular function which I realised needn’t be public, so I went to add the “private” modifier to it. In an instant of indecisiveness, though, I couldn’t remember whether I had to write “function private” or “private function”. Something flagged up in my mind that “private function” had a “real life” meaning, a function which the general public were not allowed to attend, and I wondered what it would be like if the code in front of me was one of these. I imagined people being turned away from it, which is what the compiler or interpreter would do if someone tried to run the function. Then I thought of all those “A man walks into a bar…” jokes, and the rest started to write itself. What’s next, a blog post explaining what the words of the national anthem mean? Comments
Display comments as
(Linear | Threaded)
What the!? I think I missed your joke! ;-)
public class ChessBoard {
public Square getSquare( int x, int y ) {
return new Square();
}
public class Square {
public Piece getPiece() {
return null;
}
}
}
Access modifiers on methods work just the same for inner classes, as normal classes. The interesting thing in Java is that the JVM doesn't know about inner classes, they are implemented as a compile-time 'hack'.
[...] I have already blogged about the problems with just trying to get Ctrl+Backspace working in the console, and some of the trouble getting unicode characters to work, but these problems are not exceptions, they are endemic and unavoidable, stemming from the failure of the current console paradigm. [...]
Thank you Peter Taylor for your rigorous explanation of the relevant Java syntax. It seems that I was so caught up with explaining (or trying to find) the comedy in the joke that I forgot to analyse it from a strictly formal point of view. I should have pointed out that the joke is abusing the nomenclature, since it uses "private" to mean not just methods with that access modifier but also methods which are "out of scope" (and, as you point out, these can still be "public"). Of course, the two have completely distinct definitions, and there are two different errors which result from trying to access them. Hopefully, though, the idea of being out of scope is similar enough in common usage to the idea of something being private, which is what the joke relies on. Perhaps I should have titled the section "Make sure you learn your Java definitions correctly, or you'll end up making questionable jokes like this:".
|
QuicksearchCategoriesSyndicate This BlogBlog Administration |
Having waited patiently for over 18 months, I have finally been rewarded by a solution to the Ctrl + Backspace problem which I blogged about.
Tracked: Jul 26, 23:08