Thursday, February 15, 2007

Nothing New Under The Sun vs. You Can't Teach An Old Dog New Tricks

I mentioned in an earlier post that I'm doing a bit of 'remedial software engineering' at my new job. This project involves taking a large bit of legacy code, and re-organizing it. After talking about it with several of my colleagues, it occurred to me that the proper way to do this was to split the functionality up into Unix-like filters that can be piped together.

Filters and pipes are just one of the reasons that programmers tend to fall in love with Unix. In general, a program that acts like a filter reads data from a standard input, performs some operation on it (select part of it, change part of it, sort it, etc.), and then writes the result to the standard output. A pipe (or pipeline) consists of a string of filters, each of whose output becomes the input for the next filter in the pipeline.

This is an extraordinarily powerful idea. It allows the programmer to concentrate on having a program do just one thing (e.g., select all of the lines in a file that contain a given string), yet be able to use that program in conjunction with other programs to achieve some more complicated results.

Consider a simple example. Here are some commands that work on my Linux machines here at home:
  • 'ps -e' = list all of the processes currently running, showing their process IDs and their names
  • 'grep ' = read all of the input coming into the program one line at a time, but only write out those lines that contain .
  • 'wc -l' = read all of the input coming into the program one line at a time, but only write out how many lines were input
By themselves, these program are certainly useful, but using the pipeline notion, I can quickly combine them to do something very useful. Suppose I wanted to know how many processes my webserver had running, ready to answer web requests from outside. Since I know that the webserver processes are named 'httpd', I can then answer my question like this:
ps -e | grep httpd | wc -l
(The vertical bar symbol is called, appropriately enough, the 'pipe' symbol.) The above command line first executes 'ps -e' to get a list of all the running processes, then puts the resulting list through 'grep httpd' to select only those lines in the list that contain the string 'httpd', and then counts those. Of course, I could have written a program to answer this question. However, since I have these filter-type programs, and pipes, I didn't need to write anything new, but could simply string together the functions that I needed to solve my immediate problem.

The filter/pipe idea is so powerful and useful that even competing operating systems, like Microsoft Windows, have borrowed it. Microsoft's DOS, which Windows sits on top of, implemented a very similar kind of idea years ago (but of course long after Unix had it). Neither Unix nor DOS, nor any other operating system that I know of, has come up with an approach that really matches the power and simplicity of this idea for organizing computation.

All of the above was just to explain the notion of filters and pipes so that you could understand what I wanted to do with the legacy code I inherited. My idea has two key parts. First, re-group the existing code into discrete, well-defined chunks, each of which takes some standard kind of input, performs a single operation, and then returns a standardized kind of output. Second, implement some sort of framework that allows the user to choose these well-defined chunks, and string them into a desired sequence. With this scheme, one can quickly put together a system to solve a particular problem without having to write a customized piece of code to do it.

All of that seemed like the obvious way to go. Then I began having second thoughts. Perhaps one of the (dis)advantages of growing older is that the absolute certainty of youth slowly gives way to the gray-colored ambiguities of middle age. Was a pipe/filter scheme really the best way to handle this design? Would a more integrated platform be a better approach? Was I so stuck in a particular mindset that I could not see a better way to do it? Is there a better new trick that this old dog just can't learn?

I sometimes fear that is so. When I bump into new software development approaches (Java and its menagerie of associated folderol comes to mind), there are times when I just can't make myself buy into it. In fact, I find myself making excuses to avoid having to use the new approach. It feels like the costs of learning the new system far outweigh any visible benefits of doing so. However, if I am honest with myself, that might simply be because of an old-dog syndrome.

I don't have an answer to this particular question with regard to the task at hand. So, I guess I'll proceed along the path that I can see. Unfortunately, it can be demotivating not be sure of the wisdom of one's approach.

Thursday, February 01, 2007

Multiple Desktops

It's no secret or surprise that I greatly prefer Linux to Windows for a working environment. However, reality being the stubborn and uncompromising force that it is, I've found myself increasingly having to use Windows just to decrease the amount of friction in my life. Ideology is for the young.

That said, there are some things that Linux provides that I have sorely missed in Windows. One of those is the ability to have multiple desktops. That is, under Linux, I can have, say, four desktops active at the same time, with different windows open on each of them. Moreover, I can switch back and forth between them with a keyboard shortcut, or a mouse click in a special widget on the taskbar.

People who have only used Windows are always puzzled by this concept. "Why would you want to do that?" they ask me, with genuine befuddlement evident in their faces. The reason for having multiple desktops is that it allows me to separate my concerns, to organize my work into distinct places that help me keep my tasks straight.

Here's another way to think about it. Would you want to live in a house with only one room, where your refrigerator, your toilet and your bed were all within the same four walls? Unless you are pathological in some way, the answer would clearly be "No way!". However, that is precisely the predicament that Windows users are in every day.

Using four desktops, on the other hand, I can put email on one, iTunes and other media players on another, my current major task on a third, and still have a fourth desktop available if another important task pops up later in the day. When that second task pops up, I don't have to futz around minimizing windows and such to clear things away so that I can work on the new problem. I just switch to a new desktop, do whatever is needed to, then go back to my previous task's desktop. In the meantime, I can also handle a bit of email, and fiddle with iTunes to pick another playlist. And one is not limited to four desktops. There were occasions a few years ago when I made regular use of eight desktops, although that was really more a symptom of a problem with the way my job was defined (or rather, not defined).

Sure Windows let's you minimize and maximize individual windows easily. However, that does not really address the fact that a working context almost always involves two or more windows. For example, when I'm programming, I have at least one window running a code editor, and another where I can test the code. When I'm composing an email message or working on a document, I am usually looking at other email messages, documents, or web pages someplace else. When I'm updating my calendar, I'm looking at email, to-do lists, and the like.

Each of these sets of windows constitutes a working context. You use all of the windows in a given context, shifting your attention quickly back and forth between them. Having to minimize/maximize or shuffle windows around with mouse clicks is a big impediment to productivity. It is this problem that has made the use of multiple monitors more popular lately. However, multiple monitors are not really feasible for the laptop user, or for the budget-constrained.

The real problem arises when I want to go back to an earlier context that I was working in. With a single desktop, I would have to bring several windows back into view at one time, either by maximizing windows that I had previously minimized, or by riffling through all the windows open on the screen to get the ones I wanted back "on top", that is, in view. That is simply too much bother most of the time, so my productivity slowly drops as I lose track of where I am. In fact, I often found that I have had to open the same window two or even three times because I could not find it when I need it.

So, given the need to have multiple desktops in Windows, what are the choices? Lately I have taken to checking out the ever-growing pile of well-done posts at Lifehacker.com, which is an outstanding multi-author blog devoted to personal productivity. They have done several posts over the last year or so about tools for multiple desktops, or as they refer to them, virtual desktops.

The first of these tools that I tried was Virtual Desktop Manager, which was one of Microsoft's PowerToys. These are apps that you can find on Microsoft's website, but which come with this proviso:
We take great care to ensure that PowerToys work as they should, but they are not part of Windows and are not supported by Microsoft. For this reason, Microsoft Technical Support is unable to answer questions about PowerToys. PowerToys are for Windows XP only and will not work with Windows Vista.
Given that ringing endorsement, I thought it only fair to give it a try. Although the Virtual Desktop Manager did in fact more or less provide multiple desktops, it was flat-out buggy. In particular, it kept losing windows. I would open a window on one desktop, switch to a different desktop, and then later switch back, only to find that the window was gone, or at least invisible. I could see from the Windows Task Manager that the application was still running, but there was no way to access the window. I suffered through this for a few days, and then uninstalled it and went looking for something else.

Next I tried Virtual Dimension, which Lifehacker listed as a 'Download of the Day' for 4/27/2006. It worked pretty well, and was nicely configurable. The basic application worked well enough that I never even got around to checking out a lot of the options that it had. Sadly though, it began to really annoy me. Once in a while it would simply close down a window. This seemed to happen most often with Windows Explorer, so there was no real harm done. Also, it had an odd penchant for opening new windows on the wrong desktop. This happened most often with Internet Explorer. When I was using Microsoft's Outlook Web Access in IE to access email for my new employer's mail, Virtual Dimension would sometimes open windows for new mail messages on the current desktop. However, most of the time it would open them on some other desktop, usually one where I had previously moved a mail message so that I could work with it. It took me a while to figure this out, because of course there was no indication that the window I wanted was already open somewhere else. One of the most annoying things was that for some applications (such as MS Access, which my new employer uses to track our time), Virtual Dimension would show the same window on every desktop, thus defeating the raison d'etre for multiple desktops.

My annoyance level got high enough that today I decided to try out another multiple desktop tool. I went back to Lifehacker and found another package called Dexpot, which was the Download of the Day for Dec. 28, 2006. It also had good reviews from other Lifehacker readers. Other good signs are that (1) it was produced by a German software company, who (2) gives away the product for free to individuals, but charges for companies. If they expect to charge for it, you'd hope that they would have spent at least a little bit of effort with software quality.

Dexpot installed easily. It has lots of configurable features that I've only begun to check out. The biggest thing for me, though, will be that it not lose windows, nor put them in the wrong spot. So far, so good.

Of course, I wouldn't have to mess around with any of this in Linux, whose window manager software works reliably, and which doesn't drop windows, move them around spontaneously, or make them show up in multiple places unexpectedly. Microsoft is still trailing behind, not providing features that other operating systems had years ago. I guess I should be grateful that the folks in Redmond haven't made it altogether impossible for third-party software vendors to at least attempt writing applications to make up those deficiencies in Windows.