Category Archives: FussyLogic

Finally, No

Why doesn’t C++ have a finally block? Here’s some Java. void userFunction() { f = new Resource(); f.open(); try { // might throw buffer = f.read(); } finally { f.close(); } useBuffer(buffer); } It’s tempting, after you’ve had a finally for a while to think that it’s necessary for proper resource management in the face… Read More »

C++11 Quine

A Quine is a program that takes no inputs and produces its source as its output. “No inputs” includes its source. They are an interesting little computational trick, and it takes a while to understand what’s happened. For a long time, C and C++ quines have been among the more complicated because they have never… Read More »

Not Everything Is A Reference

I like Java as a language. Kind of. It’s strongly and statically typed, has object oriented syntax, reflection, exceptions, and interfaces (interfaces being one of the few features that I think C++ is missing). Dynamically typed languages encourage sloppiness, and don’t help you avoid sloppiness, and the overriding feature of all good software is that… Read More »

Invisible Races

When you’re writing multi-threaded applications, the problem you are working hardest to avoid is that of data races. Here’s an example (assume a 32-bit x86 system): int global = 0; void thread1() { global += 1; } void thread2() { global = 0x10000; } The race here is pretty obvious. Two threads are accessing the… Read More »

Copy and Swap Idiom

I learned a new trick today, while reading about C++11 (of which more to come). It’s a technique I wish I’d known about a long time ago, as it addresses an issue I’ve always thought C++ had – forcing you to duplicate code. That issue is addressed even more thoroughly with C++11, which has introduced… Read More »

UNIX’s Achilles’ Heel I

UNIX has one (to my mind) big hole in its API. Windows, surprisingly, doesn’t share it. This article will discuss that gap, and how it can be worked around. File Descriptor Wakes There are a few multiplexing system calls, select(), poll(), and epoll() that put a thread to sleep, with the wakeup triggered by activity… Read More »

Android Authenticators I

I found a blog that gave an example of how to make a custom authenticator for Android. I didn’t find it very clear, so this article covers my understanding that I’ve pulled this together from the example given by that blog author, and from the Android documentation, and then building something that works. To make… Read More »

Burning MPEG4 to DVD From Linux

(TODO: Find out how to get aspect ratio correct.) Sometimes you want to turn an MPEG4 (or anything else you might have) from, say, your digital camcorder into a DVD that is playable on a standard DVD player. It’s not quite as simple as it should be, but it is a mechanical sequence. First we… Read More »

The Truel

Three men insult each other’s honour. They decide to settle the matter like gentleman: pistols. The pistols are single shot; and each man gets one shot. The problem is that there are three of them, not two, so this is a truel not a duel. Their respective skills with a pistol are not equal; Mr… Read More »