Why does Software Suck? Part I Sunday, January 3, 2010 at 11:01 pm

Anyone who has used a computer for any length of time has seen it. The program suddenly loses data, it goes slowly for no reason at all, it freezes, your operating system crashes. If you are on a Windows, this can be met with useful messages like “A fatal exception 0E has occurred at 002D:4C21000E” graced with a gentle blue background. Thank you, Windows. (Although newer versions try to avoid showing you the infamous blue screens of death). On a Macintosh, OS X crashes by giving you a little translucent pane in gray with the words “You need to restart your computer” in four languages. Contrary to popular belief, crashes are not more pleasant with beveled edges. Thank you, Apple.

Why does this happen? The personal computer market started in the 1970s. It is now the year 2010. Why haven’t we had more progress in creating reliable systems over the past forty years? The short answer is that we have had progress – vast progress, think back to something even as recent as Windows 95 – but the progress has been slow and halting and there’s no time in the foreseeable future that we will have widely-available multi-purpose computers that do not crash, or that perform uniformly quickly and reliably. A little introduction to computer hardware and computer history is necessary to demonstrate why I believe this. So in part 1 I’m going to explain what all programs generally and the operating system specifically has to do to even get off the ground, and the historical reasons why the machinery we’re using is a mismatch for the tasks we are trying to do; and in part 2 I’m going to go through why programming anything at all correctly is somewhere between extremely difficult and impossible.

Computer hardware was originally designed, and continues to be designed, based on something called the Von Neumann architecture. The quick-and-dirty summary of the Von Neumann architecture is this: there is a piece of hardware which contains space for a set of instructions (we call this a program) which is then sent to a processor that executes all thosetente instructions.* If the program needs to store any information, it can put this in memory (RAM, hard drive). This is how computers have worked since they first appeared, and all in all, it’s a pretty functional system. However, notice something: this system of hardware implicitly assumes you are only running one program at a time. There is space for one set of instructions to be run on one processor. Which works great until you want the machine to do more than one thing at a time – for example, use a text editor and download internet content, or play music and scan for viruses (or a million billion other common tasks).

But computers are fast – this was the whole point of them, performing complex and repetitive mathematical tasks quickly – and it is possible to execute many hundreds of thousands of these instructions sequentially at a blazingly fast rate. So to get more out of them, it would be nice to run multiple programs (in the architecture we’re discussing, these are instruction sets) at once, right? So to get around the single-program structure of the Von Neumann architecture, software engineers came up with something that is basically time-sharing.

Let’s assume you are rich. Maybe you are, I don’t know. Let’s further assume you own a summer home on the beach that you and your wife (or husband) take the whole family there for three months a year. The rest of the year, that real estate is just sitting there, unused but still costing you money. You come up with this great idea: let’s rent it out to other families during the rest of the year. That way it’s still getting used and we’re making up a little bit of the cost for it.

This is exactly how multi-processing (executing multiple programs at once) works. The beach house is your computer’s processing hardware. You (and the other tenants) are the programs that run on it. To execute multiple programs on a piece of hardware that was fundamentally designed to run one program at once, we time-share. The process of switching tenants is called “task switching” – one program is taken off the processor and all its data and everything it’s doing is stored precisely in memory so it can come back on the processor later without knowing anything has happened at all. (Think of Han Solo frozen in carbonite.) Then another program is taken from memory and put on the processor and starts up. This happens many, many times a second.

So everything should be solved right? Not quite. When you time-share a beach house (or computer), you are somewhat at the mercy of the other tenants. You could come back to your beach house and find it totally trashed. Blinds askew, furniture toppled, hairballs and cat fur everywhere. You could be stuck cleaning up a previous tenant’s mess. The same is true for programs that get plopped back on the processor, with one key difference: unlike you and I coming back to our beach house, the program doesn’t know that it has been away. It was just frozen in time, stored, and then restored. It has no way of knowing that someone else was using its house, and usually can’t tell that any time has passed at all. It can’t take a look around because it doesn’t know that anything has changed. So the program is going to continue as if nothing has happened, and if something has happened – if a piece of memory it had assumed was one thing was accidentally changed by another program, for example – well, that’s when you get strange behavior and program crashes.

This brings us up roughly to the Windows 95 era. This is when you would select Start > Shut Down and there would come up a screen saying “It is now safe to turn off your computer.” And everyone recommended you to restart your machine every day. Why? Well your computer was only the one beach house and after having all those tenants in it it was impossible to assure everyone that the place was just like they expected it to be. So it was not uncommon for programs to tread on other programs’ toes, so to speak. Best to just reboot the whole thing so you know where everything is.

The computer operating system was originally a program that was designed to provide support to other programs – a kind of library of common operations. Do you need to draw something on the screen? Do you need to find out what the time and date is? Do you need to write letters to the screen and read from the keyboard? The operating system can help with that! The operating system would also help boot up your computer and allow you to navigate around the file system. As we moved more and more toward multi-processing, there was another place the operating system could obviously help with: keeping processors separate so they didn’t interfere with each other. And this is just what was developed. The system is called “virtual memory” – and while it’s not important to get into the nitty-gritty, it’s basically carving up the time-shared house into different rooms for each program to live in. Although a program has full control of the processor when it’s running on the processor, in order to access storage, it now has to go through the operating system – and what the operating system does is it lies. The program thinks it’s accessing one place, but the operating system actually keeps a separate copy of every location for every program so they can’t interfere with each other. In fact, there is no way they can access each other’s storage, even accidentally. The operating system is the tidy butler keeping every tenant separate so that no one else has to see their mess. And ideally, none of them will realize that anyone else is ever there.

This seems really great, but where this opens pandora’s box is when it comes to what computer programmers call “threading.” Threading is getting a single program to create several copies (or forks) of itself. Why on earth would you do this? As programs have become more complex, it has become obvious that not only do you want multiple programs to run simultaneously, but you want a single program to do different tasks simultaneously – like spell-checking and doing a word-count. It just speeds everything up! Thus, “threading.” Each thread usually has a different job to do (if you work in the corporate world, think on how many things Microsoft Outlook is doing at the same time – checking mail, checking your calendar, looking at a to-do list…). It’s not uncommon for a large program to be running dozens of threads. And remember, these threads are treated just like different programs by the operating system** – so they are taken on and off the processor dozens of times a second. If this seems like it could get complex very quickly, it does – it is easy to have threads lying around that aren’t doing anything, but are taking up time on the processor, or threads that are all waiting on each other to do something and never do anything themselves (thread deadlock). Threads make a conceptual mess very, very quickly. And when looking at how many different processes are having to be taken on and off your processor, threads add up just like programs. The overhead of having to freeze and store all of a program or thread’s information, and then bring another back from memory to start running adds up much more quickly with threads involved.

The supposed answer to all this is multiple processors, but these are a long way from being an ideal solution – or even a workable solution. To some extent, you can run multiple programs better with multiple processors. But the way these have been designed, they are still accessing the same memory, and the hardware infrastructure around the processors was designed for one, not two of them. So they cannot both access memory at the same time. One processor cannot talk to the other very easily, and so running multiple threads from one program across multiple processors is difficult. Currently the biggest advantage to having more than one processor is you have to only do half as many task switches between threads/programs (or one-fourth, if you’ve shelled out a lot of money for one of the quad-cores). Fundamentally, we have taken two single-program processors and glued them to the same bit of memory.

So let’s summarize. The computer you are reading this on bears its internal organs from a machine designed to run one program at a time. Presently it is running multiple programs at a time by taking them on and off its internal brain more quickly than you can perceive. Not only that, but within some of those programs, it is still taking different threads on and off its internal brain, all in the pursuit of the illusion of multitasking. These internals have not been substantially redesigned from the original single-program model; all these things are hacks and small, cumulative modifications to get around it. There’s enough space in all this to drive through truckloads of program crashes and system slow-downs. And this is all just the infrastructure your computer and operating system has to support to run anything useful on top of it. Although there is some hope of things looking up eventually with multiple processors, the way they are designed now does not significantly change this infrastructure.

These are some of the historical reasons we have what we have today – we are not using our computer architecture for what it was originally designed to do, and although we’ve gotten better at it, the more complex workarounds we make for the machine, and the more adjustments we slap onto it, the more likely there is to be some point at which one of them will fail, and the less likely it is that anyone will understand why or where the failure happened.

* These instructions can include conditional statements – this is how we create programs that do different things every time depending on input – and this input can be from a human interacting with a keyboard, from a file, an internal clock, a random number generator, whatever.

** With one exception: threads of a single program will all see the same memory space – that is, they are all given access to the same rooms in the beach house.

Holiday Links Monday, December 21, 2009 at 1:38 pm

Living life tends to have a chilling effect on my ability to blog. I have at least two partially-finished posts that I’ve been meaning to complete and post, after I get all the Christmas gifts settled, and have lunch with this and that group of friends, and arrange to meet up with so-and-so when he’s up here for the holidays, and go out to this local artist’s studio (he was a really cool chap by the way), and go see the Nutcracker (mediocre), and once I start getting home at a reasonable time from work so that I don’t just plop down on the couch and watch the latest Netflix flick.* That in mind, I have asked a friend to keep me to a weekly schedule after the new year. No excuses.

But here are some year-end links for you, in spite of all that. Mostly it’s some of the cool and/or important stuff I’ve found over the year and shared out through my Google feed:

First up is the anti-gay hysteria going on in Uganda. Box Turtle has done a brilliant job of covering this story. (If you’re wondering where the title “Slouching toward Kampala” comes from, check out this poem by Yeats – classic, important bit of cultural English-language knowledge. You should know it.) Uganda is already a hotbed of anti-gay sentiment, and the fire was inflamed when some American ex-gay activists went over for a conference to proclaim that gays could be “cured” from homosexuality if they really wanted to be. Those activists have, of course, done a miserable job of distancing themselves from the draconian new legislation that was proposed a few months after their arrival, as also the international Anglican Church and many American pastors with ties to that country have had very mild rebukes. This legislation makes the typical anti-gay (and in this day and age, unexcusable) slur conflating homosexuality and pedophilia, and among other things it makes “repeat homosexual offenders” (e.g., those who have had sex more than once) and persons guilty of “aggrevated homosexuality” (among other things, HIV positive gay men, and remember this is in a country that is part and parcel of Africa’s severe – and largely heterosexual – AIDS crisis) liable for life imprisonment or death. Under this legislation, anyone who knows someone is gay and doesn’t report then to the police within 24 hours is liable for several years’ imprisonment. Oh yes, there is also a provision for extradition for these offenses committed in foreign countries. It is very likely that this legislation, or some form of it, will pass. This is a glimpse of what total minority persecution and anti-gay hysteria looks like. For a look from a gay man on the inside of Uganda, check out Gay Uganda - an excellent source of both inspiration and heartbreak.

On an aside, not a good year overall for gay marriage (but in Washington everything-but-marriage domestic partnerships passed by popular vote; YAY). This guy has great videos rebutting some of the absurd distortions put forth by conservative religious groups arguing against same-sex marriage. On religious freedom here, and he covers all the arguments I’ve heard on that front, and on ”bashings” here and religious misunderstandings of it - both videos are chock-full of information you ought to know if you want to argue for gay marriage. I highly recommend both.

Second is all the information about American-perpetrated torture that’s come out this year. Glenn Greenwald has, as always, been a great champion of human rights and provider of critical information in these cases: here is his post responding to and highlighting pieces of the Inspector General’s torture report, and here again on a British high court’s order to release information about British complicity in US torture (our government has purportedly sliced open a man’s testicles with a scalpel, you know, to protect us from The Terrorists). Sullivan posts on it here. And here is the disturbing 2004 report on Guantanamo detainees from the International Committee of Red Cross. I’ve watched with dismay as the discussion has shifted from whether the US tortures prisoners, to whether it’s okay that the US tortures prisoners, to asinine defenses of “moving forward” and why we shouldn’t prosecute anyone for flagrantly breaking the Geneva Conventions which this country’s legislature signed into law (and is therefore constitutionally the supreme law of the land), until eventually this discussion has moved altogether into obscurity. The ACLU has an interview video with British detainees released from Guantanamo; this video should be required viewing for all Americans. Even more depressing than all this is the uncritical acceptance of these practices by certain religious persons in this nation; what good is religion if it is not grounded in a deep sense of justice? But then again, I’ve come to decouple justice from religion, as is necessary for anyone witnessing the actions of some, but not all, devoutly religious persons. But I digress.

But while we’re on the topic of religious insanity, the Slacktivist as always continues to be a point of relief from evangelical insanity. For those of you who don’t know, Fred (the Slacktivist) is himself an evangelical Christian who on his blog routinely takes to task many of the absurd and even evil things propogated by those claiming his faith and the name of Christ. From evolution denial to his Left Behind series (some sort of mass internet therapy for those of us who grew up with the books and have been scarred), Fred is always a good read.

And now we come to the random links. Jason Kuznicki makes a convincing case that Athenian pederasty, as awful as it was, was probably less morally objectionable than Athenian marriage. Classically Liberal makes the case that sex offender laws more often capture consensual teenage sex than actual predators. XKCD captures my feelings about the odious Papyrus font. Liu Bolin, a Chinese artist, wins my award for best art I’ve seen this year. And if you like stunning photography, an interview parts one and two with Art Wolfe.

I leave you with a quote:

The question of how to spend my life, of what my life is for, is a question posed only to me, and I can no more delegate the responsibility for answering it than I can delegate the task of dying.

- Anthony T. Kronman from Education’s End: Why Our Colleges and Universities Have Given Up on the Meaning of Life

 

* Recently I’ve been getting into Mad Men. I hate Don Draper with a passion but it is an excellent show. Presently Terry Gilliam’s Brazil is sitting at home waiting for me.

Why Series: Why Economics? Sunday, November 8, 2009 at 3:40 pm

I have been wanting to start a new series of posts on this blog, a series that I have come, at least in my mind, to call Why. Why do things work the way they do? This is not an attempt to explain the mysteries of the world and the universe and existence, just to ask questions, and maybe to find some possible answers. To explore. If I could answer such questions with certitude, I’d either be certifiably insane or the supreme dictator of the universe. I’m clearly not the latter and I hope I’m not the former, so I’m looking at this as an exploration – a journey – rather than a destination. So these explorations will typically take the form of ‘Why does [some phenomenon] happen?’ or, the shorthand ‘Why [some phenomenon]?’

Why blog about this at all? It keeps me accountable to actually asking questions – questions l may otherwise avoid out of laziness or complacency – and doing diligence to find reasonable answers. And then, ideally, I could engage in lively conversation with you in the comments and we could all come away more enlightened. Although I have some ideas of the first few things I want to look into, including some that I happen to have some insight into (for example, Why software sucks – and no, it’s not because Microsoft is evil, my Maccy and Linuxy friends, or anything so simple as that), I’d like to take suggestions of what to look into. So if you have an idea, submit in the comments or contact me.

Today is a rather light one: why economics? Not why does the economy work the way it does (clearly almost no one understands that or we wouldn’t've gone through the subprime-mortgage-induced credit crash), but what is economics and why does it exist in the first place?

Wikipedia, the world’s best source of eighty-percent accurate information, defines economics as “the social science that studies the production, distribution, and consumption of goods and services.” That’s a decent enough definition, and I’m willing to accept it with one caveat: that we define the term “goods” to include all scarce resources, real and socially-agreed upon. Let me unpack why I defined it this way. General “resources” so we are not limited only to manufactured goods, but we can include natural goods like beaches, gold, fresh water, and even (in a society with slavery) other human beings. “Scarce” so we can safely exclude goods which are, for present purposes if not in reality, unlimited (e.g., air or solar energy). “Real or socially-agreed upon” because this allows us to consider things like beaches and computers alongside patents (one socially-agreed upon “thing”), and sunlight rights (which is in fact a scarce commodity among the towering buildings of Tokyo). My definition may not be expansive enough, but I feel it’s a good start.

Depending on what terms your favorite science-y author likes to use, humans are hypersocial, supersocial, or ultrasocial creatures. I first came across this concept in Jonathan Haidt’s phenomenal book The Happiness Hypothesis, where Haidt looks at the science of social animals before looking at human sociality, and applying that to human happiness. Although a discussion of how animal ultrasociality works is far beyond what I want to look at here, suffice it to say humans are the only animals we know of that demonstrate sociality that extends beyond kin altruism (helping out other individuals that share a significant amount of genetic material). Humans have developed a complex series of reciprocity-based moral intuitions and tribalism to handle altruism beyond kinship, and the upshot is that we can band together and better survive as a group but still attempt guarantee a benefit to the individual. And this also means that we live in a world formed not only (or even primarily) by our physical environment – grass and trees and apartments and grocery stores – but also in a world of complex social ties of reciprocity and altruism and betrayal and kinship and love. You and I are not cats or horses, who are concerned only with next-of-kin and finding food and copulating. We have these webs of social interactions which give rise to non-kinship relationships like friends and nations and the mafia and a thousand other things. The fact that these social webs exist, regardless of what evolutionary or other process created them, I regard as so obvious it doesn’t require defending. But here we are, and these things exist.

So if economics is the travel and distribution of goods, where do they travel? Obviously among these social webs. This distribution of goods exists in other animals too (a pack of African Dogs may “own” the meat of a kill), but at nowhere near the level of complexity as humans, because African Dogs do not have the same set of complex social interactions. Sometimes goods travel in one direction (e.g., through extortion or bribe or military conquest), but typically two entities come together and they both exchange something that the other entity wants. This is why economists say things like “economics is not a zero sum game” – usually, everyone gets something they want.

But however the details of economics play out in different societies and between societies, we have this thing called economics because we have scarce resources and we are ultrasocial beings. We don’t all simply horde what we have and refuse to exchange goods with one another, and we can’t magically create everything that we want and so are limited by how much of a good exists. And so we engage in distribution and movement of goods, and everyone tries to benefit themselves and their social webs. Economics exists because of scarce goods and human sociality. These two things both give rise to economics and they are the rules of the game.

Zion National Park Saturday, November 7, 2009 at 11:17 am

You know the drill: more photos. This time from a mini-vacation I took with my dad a month back. Zion is one of my favorite places in the world, but I was a bit disappointed at our mutual ineptitude at getting a back-country pass. Oh well, it was loads of fun anyway (with a few scares, but we’ll leave that aside).

Zion Canyon from Angel's Landing

Backside of Zion Canyon

Kolob Canyons from a Distance

The Virgin River Narrows

Wall Street at the Narrows

This is where we had lunch

Vertical Space of the Narrows

 

When You Can’t Make it to the Top Sunday, October 25, 2009 at 5:09 pm

I failed at summitting Mt Adams this year. Adams is (for most people) a two-day summit, and I had been looking forward to doing this climb all summer. Granted, this was two months ago at this point, but it was very sad. I got altitude problems at our overnight campsite (called “the lunch counter” – lunch not included), and then was unable to continue after only a thousand feet or so the next day. I admitted to our hike leader that I wasn’t going to make it up (as if it wasn’t obvious from my falling further and further behind), who agreed that I wasn’t going to and we should head back down. The rest of the group – four guys in all – headed up, but the two of us started to turn back down. This alone was sad enough, but it was the next bit that was awful and embarrassing.

This past summer was unusually hot and came unusually early: the result being that the mountain was nearly-bare for our ascent. We did it without crampons, scrambling over the rocks just to the side of the remaining packed snow above the lunch counter. However, our camp leader brought crampons anyway and after I had decided to turn back, loaned me them to get back down to camp faster. I had never used crampons before and despite my friend giving me instructions and help with a couple of steps, within two minutes of stepping out onto the snow, I planted my foot, tried to turn it (feet in crampons don’t turn), and fell down and twisted my ankle.

Several expletives later, and after getting my bearings, I tried to get up off the snow. My friend was beside himself, certain it was his fault despite however many times I told him it wasn’t. But I was not walking long distances anytime soon. I found it impossible to put much weight on it, and I hop-moved off the packed snow and back to the rocks, where we made ourselves warm and tried to figure out what to do. After thirty minutes to an hour I was still unable to put weight on it and we called for assistance. It sounds simple but we spent a good fifteen or twenty minutes trying to get a cell signal, and then asking the emergency responders on the other side what to do, then waiting for a call back, then arranging for a ranger to come up and take a look, then waiting for another call back, and on and on and on.

So we waited. Nerve-wrackingly. It is cold to wait on the side of a mountain for hours (we were at about 10,800 feet if I recall). But we couldn’t've asked for better weather to have this happen in: clear skies and sunny, so we were at least heated by the sun. I took out my ankle and it was a little swollen (not as bad as I imagined – I had an identical injury on the same ankle the previous month playing tennis, and had a swollen knot the size of my fist for two days afterward) but it was still too sensitive to walk on. Eventually the ranger came up, and the rest of our party met us on their way down. The ranger looked at my ankle and tried to dress it but couldn’t do much. It would be tedious, long, and difficult to get a group up the uneven rock field to carry me off, and it would take at least half a day to get them in place, meaning it would be night or the next morning before the team could be up. Feeling the little nudge – or giant cattle prod – in my head not to be a wimp and be pulled off unless I were in the worst, most debilitating pain of my life, which this was decidedly not, I said that I would make it down. We made our way back to our campsite by glissading down the strip of packed snow that we had followed beside much of the way up. Besides being fast (and fun), glissading had the benefit of keeping my weight off my ankle for much of the way down.

We made it back to camp and my compatriots, as well as the ranger (who followed and assisted us all the way back down), were noble enough to take most of the weight of my things on their backs instead of mine, and we made our way down the five or six miles of trail to the parking lot. And I made it just fine – well, until the next day when my ankle swelled back up and hurt worse than the day before. But civilization has much more ibuprofen than the mountain wilderness.

What’s the moral of the story? A couple things:

1. To use a phrase I have only recently become acquainted with, I am athletically retarded. I come from a long lineage of tall, athletically retarded but athletically determined (and hence, accident-prone) men, and I am no exception. I know I have thin and fairly weak ankles and now I wear an ankle sleeve brace on the troublemaker whenever I know I’m going to be doing something demanding.

2. Rangers are awesome.

3. The five other guys I went with are hosses. Seriously. I wasn’t the only injured one, another friend had terribly blistered toes (not normal-blistered, made-my-skin-crawl-when-I-saw-it blistered) from his boots most of the way up and down. Another one had been on who-knows-how-many hikes and summits this year alone, and still another had summitted Kilimanjaro. And they were all both good company and kind.

4. I am trying again. Don’t know if it’ll be next year or not but I will summit it. I was less than 2000 (vertical) feet short of the top this year! Just because I’m athletically retarded doesn’t mean I’m gonna let that stop me – within reasonable limits. And next year I will know how to use crampons appropriately and go earlier in the season when there is more snow for a smoother ascent and descent.

 

Seattle Summer Saturday, October 3, 2009 at 1:26 pm

What, I have a blog?! Yes I know it’s been quiet lately…

Here are some assorted pictures from around Seattle over the summer. Most of them are from Mt Rainier because, honestly, Mt Rainier is just awesome.

Waterfall at Mt Rainier

Mailbox Peak

Mt Rainier at Dawn

Mt Rainier at Dawn

Mt Rainier at Dawn

Mt Rainier at Dawn

Mt Rainier at Dawn

 

Mt Shuksan Sunday, May 17, 2009 at 9:33 pm

EDIT: I stand corrected. These are pictures of Mt Shuksan, not Mt Baker. My first time up there, so I plead ignorance.

These are about a month old, but here are some pictures taken of Mt Shuksan. They are all HDRs, some converted black and white, some desaturated. Enjoy.

Mt Baker

dsc_0020_1_2_3_4_tonemapped_color_3

dsc_0012_3_4_5_6_tonemapped_v4_3-3

dsc_0026_27_28_29_30_tonemapped_bw_2