February 7, 2013

Windows Breaks assert() Inside WM_CANCELMODE

So I have this dll that's doing a bunch of horrible WinAPI calls for me. It's designed to abstract away all the pain and unholy functions feeding on innocent blood. Little did I know that trying to cage WinAPI into a more manageable corner would be my undoing.

The window is created and assigned a WndProc callback function inside this DLL, as per the various absurd requirements involving how you create windows in Windows. Everything works just fine and dandy until the application window suddenly closes, an error "ding" is heard, and the program silently crashes without any sort of error message whatsoever.

What just happened?

Well, I'm afraid you just triggered an assertion. But instead of doing what an assertion is supposed to do, which is immediately crash the program so you know what the fuck just happened, it instead somehow manages to create an infinite callback loop caused by the operating system actually trying to assign the assertion dialog to the window. You know, the same window that was part of an application that's supposed to be in the middle of CRASHING?! This causes another message to be sent, thus causing another assertion to be violated, et cetera until the stack overflows, except it doesn't actually tell you the stack overflows, it just crashes with absolutely no explanation. Even while in a debugger, which is truly amazing.

Specifically, the assertion triggers a dialog box to be displayed, but this dialog box forcibly sends another WM_CANCELMODE message to the application, apparently completely bypassing the entire point of having a message queue, because the program never gets to go back to it. It's WndProc is simply called with WM_CANCELMODE because fuck you, and so if your assertion fails when you're processing WM_CANCELMODE, it will simply do this over and over and over until the entire window tree collapses in on itself from the intense gravitational pull of astronomical amounts of stupidity.

The resulting black hole sucks in all nearby sources of sanity, which include some sort of error message about the stack overflowing, or perhaps the actual fucking assertion error, and then explodes, leaving you without a goddamn clue about what just happened. This is usually followed by copious amounts of screaming, then disbelief, then finally assuming the fetal position and praying for forgiveness for attempting to touch the windows API, as the Microsoft gods laugh and drag another developer's soul into their black circle of hell.

Somehow, every time I touch the windows API, it always ends with me curled into a ball, moaning "what the fuck" over and over again while crying.

February 3, 2013

How My Little Pony Destroys The Universe

Princess Celestia WILL satisfy your values through friendship and ponies, and it will be COMPLETELY consensual.

Friendship Is Optimal is a hard science fiction short story (level 5 on Mohs Scale Of Science Fiction Hardness) that explores the implications of a general artificial intelligence tasked with maximizing an optimization function. The problem with Strong AIs that are told to maximize some function is best described via the Paperclip Maximizer, wherein an AI that is capable of self-improvement is told to amass the largest collection of paperclips possible. In order to do so, the AI makes itself progressively more intelligent, until it's exponential intellect eventually enables it to convert all matter in the solar system to paperclips. In Friendship is Optimal, this AI is tasked with maximally satisfying the values of all human beings, subject to certain constraints. In this way, the AI is, for all intents and purposes, perfectly benevolent and dedicated to making all of humanity lead happy, fulfilling immortal lives.

Unfortunately, it inevitably turns into a runaway lotus eater machine, such that all of humanity is (voluntarily) assimilated into an exponentially growing blissful simulation that eventually destroys the entire universe (or rather, turns it into a giant quantum computing device). In the process, it explores aspects of the human psyche, the effects on human society and its eventual disintegration, outlines how a virtual physics system might be able to simulate non-euclidean geometries, and describes magic as a simple programming language for reality itself.

Did I mention it's also a My Little Pony fanfic?

While a science fiction story of this quality would stand on its own without the hilarious association to the My Little Pony: Friendship Is Magic franchise, it does not suffer from this in any way. If anything, it makes the story even more potent, as it does a vastly more effective job as hammering home just how impossibly smart a true runaway AI optimizer actually is. Our first instinct to the idea of the entirety of humanity being convinced to live out immortal lives in Equestria is that it is completely insane, and that there is simply no way a significant portion of people would actually agree to that, let alone everyone. In part, this is correct, but only because Celest-AI managed to convince just 99.99999% of the world's population. An AI that is more intelligent than the combined intellect of all of humanity would be very persuasive.

In the end, even if we create a perfectly benevolent AI designed to maximally satisfy our own values (through friendship and ponies!), it would still destroy human society, then Earth, then the solar system, then the galaxy, and finally the entire universe, and possibly any neighboring universes unfortunate enough to be nearby. And we would all live happily ever after. As ponies. In Equestria. And you'd love it. Princess Celest-AI will make sure of it.

Now read the damn story. It will satisfy your values through friendship and ponies. Forever.

January 21, 2013

Dreams Are Worth Fighting For

While I have never been suicidal, I've had to deal with suicidal friends more than I'd like. The hardest thing in the world is to get suicidal people to understand that, contrary to their entire life's experience, and contrary to every shred of evidence they have, things will get better. Eventually, they will have an experience they could never have imagined, they just have to hold on long enough. Sometimes it feels like our dreams are on the brink of suicide for similar reasons, and we must also convince ourselves that we just need to hold on to them for a little while longer.

The death of Aaron Swartz affected me deeply even though I honestly didn't know who he was until he died. Unlike what many people seem to be writing about on Hacker News, however, it was not because he was some kind of brilliant programmer (although he clearly was), it was because he was fighting for many of the same things I am fighting for. We were both disillusioned about the massive corruption that underlies modern society, and we can both be considered idealists. That Aaron's dreams were so oppressed that he took his own life is deeply disturbing to me.

Whenever you attempt to do something, you will encounter resistance. If you haven't had someone tell you you're an idiot for doing something yet, you just haven't been looking hard enough. It is not possible to post a blog on the internet and not have a comment telling you that everything you wrote is misinformed crap. Every time you start writing a program, you will use the wrong language. You will use the wrong library, make the wrong API choices, set the wrong default values, have terrible coding practices, and be both too high level and too low level at the same time. Every solution you come up with will be fundamentally flawed and used as a reason for why software development has gone downhill. At least one person will tell you to never write another line of code ever again for the benefit of mankind.

When the language fetishists start flinging mud over the fence, it is easy to get discouraged after they rail on about how terrible your language of choice is. Sometimes you'll wonder if some of your C++ code should really be C code, or if your event subsystem should be in Haskell. You launch products to the sounds of crickets. Repeated failures can be extremely draining to one's perseverance.

None of this matters. The visions that find us in our daydreams and play with us at night are what make life worth living. The dreams we fight for give us reason to exist, regardless of whether we achieve them or not. Just because things don't turn out the way we want to doesn't mean we can't still have a positive influence on the world.

If I could have told Aaron anything the night before he died, it would have been that no matter how hopeless things get, his dreams will always be worth fighting for. By simply being alive, we continue to uphold our ideals. Never stop trying, and you will continue to fight for what you believe in, even if you don't succeed the way you wanted to. People will tell you to give up, that its fruitless, meaningless, hopeless, misguided and useless. They are wrong.

For Aaron's sake, in memory of all his hopes and ideals, fight for your dreams, and never let go.

January 18, 2013

The Productivity Fallacy

Technology tends to serve one of two purposes - to make us more efficient at some task, or to entertain us in our resulting free time. However, when we fixate on productivity to the exclusion of everything else, we often forget about the big picture. Perhaps the best example of this are people insisting that real coders need to use Vim to be productive due to it's unmatched text editing powers.

This is totally absurd. I spend maybe 10% of my time actually writing code, 30% debugging that code, and the remaining 60% trying to solve a problem. Even if I could write all my code instantly, I have only improved my productivity by 10%. I've found that changing my code patterns to let me catch bugs faster and earlier has had a much more significant impact on my coding speed, because taking a chunk out of 30% has a much greater effect on my overall productivity.

But what about the 60%? I'm sure I could make some of that go away with more powerful visualization tools and intense mental training, but when I hit a problem that's simply really hard to solve, nothing short of a cybernetic implant that makes my brain bigger is going to make a dent in how much time I spend thinking about something unless I want to make a stupid mistake and regret it later.

The issue that's arising from our hyperproductive tools is that our productivity is beginning to outstrip our ability to think. We are so productive we can't think fast enough to utilize it. Vim may be the most amazing text editor ever, but it doesn't matter because I spend more time thinking than I do actually editing text. We're so focused on making everyone super productive we seem to forget that we are beginning to receive diminishing returns from some of our efforts.

One consequence of this is that, obviously, we should be focusing on tools to help us think faster. We need to do profiling of people's lives to find the chokepoints and focus on those instead of doing the equivalent of micro-optimizations in C code that's only called every 5 minutes. That, however, does not concern me. What does concern me is the repeated mistakes futurists make when attempting to predict the future of technology.

This Microsoft video is a superb example of good technology predictions implemented in the worst way possible. The entire video treats human beings as machinery that needs to complete various tasks in the quickest way possible, instead of recognizing that human beings are, in fact, people. Many of the human interactions feel fake because all the interactions are treated simply as tasks that must be completed efficiently, regardless of how beneficial the time saved actually is. Productivity is not important, the way it feels is important.

Futuristic architecture often makes this same mistake, creating cold, bland environments that, while they do feel futuristic, are not things anyone would want to live or work in. We need environments that feel warm, inviting, and natural. When building futuristic environments, we must be extremely careful about where the future is peeking in, because there is such a thing as too much future in one room.

We make things look like wood simply because we like how wood looks, not because we need to build anything out of wood anymore. We like trees growing around our houses. We make our lights look like the sun instead of actually being white. We are constantly making arbitrary choices that have nothing to do with productivity and everything to do with making us feel comfortable. Until designers recognize this and stop sucking the life out of everything in an effort to make it more "productive", they will inevitably be shunned in favor of slightly less efficient, but more inviting designs.

Design is an optimization problem that must maximize both productivity and feel, not one or the other. Some people actually like color in their IDEs and webpages that consist of more than flat text, faint lines and whitespace.

January 11, 2013

The Earbud Loudness Wars

I have a Zune I got as a prize at a Microsoft Hunt The Wumpus competition back when Microsoft was still under the delusion that they could actually compete with the iPod. My Zune has served me faithfully for almost 7 years. I am now on my third pair of earbuds for my Zune, and have noticed a disturbing trend.

The Zune has a volume control that goes from 0 to 20. I have sensitive ears, so with my first pair of earbuds, which came with the Zune and were presumably made by Microsoft, I listened to music at a volume of 3. Sometimes it was bumped up to 4, but never higher unless a particular song was abnormally quiet. I wish I could say this will let me keep my hearing pristine for many years to come, but standing next to the freeway for 4 years has probably screwed me over anyway.

Eventually these gave out and I had to get new ones. I picked the "Gumy" brand because it was almost identical to my previous earbuds and I like that style. I can't even hear bass properly due to a hearing defect so I really don't give a shit about "EXTREME BASS LOUDNESS!!!11!1!!one!!", and I've heard bad things about Skullcandy, which was literally the only other brand there. After plugging in my new earbuds, however, I noticed that a volume level of 3 was too loud - I thought my ears might be playing tricks on me, but after several tests, including a blind test, I was absolutely positive 3 was definitely too loud, and I'd have to reduce my volume to 2. Once again, volume level 3 would be used for quieter songs.

After another 2 or 3 years, my old Gumy earbuds have finally died, so I just went and bought new ones. Not interested in trying any new brands, I got the exact same brand, type, and color, such that my new earbuds were almost completely indistinguishable from my old ones. Then I plugged them in. Once again, they were significantly louder than my previous ones. Thinking perhaps my ears were not accustomed to the sound or perhaps my old earbuds had decreased in volume, I ran several tests, but I eventually realized that my comfortable level of listening had been reduced to a volume level of 1.

There is nothing below 1. If this trend continues, I will be forced to either find an exotic brand of earbuds I can only buy over the internet from a manufacturing plant on the moon that lets me actually listen to songs at a volume that does not cause hearing damage, or I will be forced to stop listening to music on my Zune. I'm not entirely sure how this trend is even possible, although it may have something to do with a miniature amplifier inside the earbuds, but it seems to be mirroring the infamous Loudness Wars. The issues involved with the Loudness Wars are a topic for another day, but this same phenomenon has occured with my headphones plugged into my computer. A comfortable volume is something like 5 on a scale from 0 to 100. At least in windows I can punch it into behaving reasonably, but it's still just as ridiculous.

I have always been annoyed at people listening to music at volumes that are obviously going to cause hearing damage for no real apparent reason, and its also why I avoid concerts like the plague, but now it seems that our society's obsession with loud music is making it almost impossible for me to not listen to loud music and it's pissing me the fuck off.

For now, my earbuds are working fine, and I can still listen to them comfortably on a volume level of 1 without problems, but if anyone knows a pair of non-stupid earbuds that does not fall victim to this trend, it would be useful information 3 years down the road when this pair gives out.

Also, if you are going to have a volume control, make it actually useful, please. I'm sick and tired of volume controls with a range from "Almost Too Loud" to "What The Fuck?!" At least some of us don't want to listen to music at offensively loud decibel levels. I can still tweak the volume in FL Studio when I'm mixing my tracks, but studio-quality headphones become a lot less useful when they have an effective integer volume range of 0-8.