Archive for June, 2008

Binary search for lower bound in C

Friday, June 20th, 2008

Blogging from my wife’s BlackBerry here… while I’m watching the kids outside. Should be fun!

I recently ran into a work problem where I had to find, in a sorted array, the largest entry smaller than my input number. You can approach this as a binary search problem, and I did at first. When Google couldn’t find a good implementation in C, I wrote one of my own, even to the point of coding up test scaffoling in the style of Programming Pearls.

But then I recognized that the problem was actually called “finding the lower bound”, which gives better search results. There’s even an implementation in STL that I could use in my target application. More on that later.

Anyway, about a week later I’ve spent so much time thinking about the damn algorithm I haven’t even put it in the target code yet!

(more…)

In which my innocent child is corrupted

Wednesday, June 18th, 2008

Background is necessary. In one episode of Dora the Explorer (that’s a children
s TV show), Dora finds a dinosaur egg which hatches. They help the baby dino get back home, all the while singing the Baby Dino song. With verses like:

Who’s got the biggest footsteps around?
BABY DINO!

Unfortunately this song is strangely catchy. So we find ourselves singing it. And we screw with the words.

Who’s got the rottenest liver around?
BABY WINO!

Who’s got the smallest tax-cuts around?
BABY RINO!

I was particularly pleased with that one. But Kaija was upset by it, and wanted to know what I was talking about. Explaining Republican In Name Only seemed beyond the scope of the situation, so I started on taxes.

“See, taxes are when the government steals your money. So tax cuts are when they steal less of your money, so the cuts are good.”

She frowned thoughtfully.

“Government bad. Taxes bad.”

And in that moment I knew I was going to Hell.

I just bludgeoned a mouse to death

Wednesday, June 18th, 2008

Fucking mouse.

Lame cat who won’t catch the mouse, even when the mouse is pointed out to said cat with a flashlight.

Fucking mouse running around my desk, on the floor and on top of the desk too.

This is a big flashlight.

Hmmmmmmm…

WAP WAP WAP WAP WAP

One dead mouse.

Threads are Evil

Sunday, June 15th, 2008

The Magician of the Ivory Tower brought his latest invention for the master programmer to examine.

I followed a link labeled “Threads are evil” to this paper (pdf, few hundred k) by the Edward Lee, who is no less than the chair of the EECS department at the University of California, Berkeley.

The thrust of the paper (which is more than two years old) is that threads are a bad model for parallel execution because they make it hard to prove things and reason about programs. I’m not trying to make him sound unreasonable, but there it is. Actual excerpt:

That is, given a pair of multithreaded programs (p1, p2) and another pair (p1, p2), when are these two pairs equivalent? A reasonable extension of the basic theory defines them to be equivalent if all interleavings halt for the same initial state and yield the same final state. The enormous number of possible interleavings makes it extremely difficult to reason about such equivalence except in trivial cases (where, for example, the state B** is partitioned so that the two programs are unaffected by each others

Rails Sucks

Saturday, June 14th, 2008

I am messing around with a new web project and decided to play around with rails again — last time I checked it out was a few years ago, and although it looked cool I didn’t have enough time then to spend on the project I was playing with.

So I updated the rails install on my machine and got started with the project.

$ gem update rails -y

I like that the new version defaults to using sqlite for the database, saves me screwing around with MySQL (that’s another post…). Then I was browsing around reading about testing frameworks and saw that Test::Rails is supposed to be the great thing since it allows you to separate view and controller tests. So I gem installed that and made the manual changes suggested.

And suddenly my tests were half broken.

It turns out that Test::Rails doesn’t work with rails 2.0 or greater. and this has been known since January. So I wasted a half hour trying to make it play before I threw in the towel and went on with rails 2.x, having to do without Test::Rails.

Overgeneralizing: this is the problem with dynamically typed languages, hype, and the open-source process in general. Eric Hodel, the author of Test::Rails, probably has better things to do (like give talks and work on lucrative projects) than make Test::Rails work with rails 2.0. The rails developers can’t be bothered to maintain compatibility with every rails-related plugin out there, and even if they did provide a patch to Hodel, there’s no guarantee it got into his official repository. It may be living out there in the wild in somebody’s git repository, but that’s not exactly helpful to me.

Of course I could fix it myself. But I’m not trying to make the ruby/rails tools better, I’m just working on my project.

I love open source, and I’m continuing with the project on rails. But it becomes clearer and clearer to me why so many people turn to safe, boring, slow, ugly — but nonbroken — Microsoft solutions.

Stupid Republican Strategy

Monday, June 2nd, 2008

The GOP has a new talking point against Barack Obama:

Obama Has Not Been To Iraq Since January 2006:

In January 2006, Obama Took His Second Trip As A Senator To Qatar, Kuwait, Jordan, Iraq, Israel And The Palestinian Territories.

Thought for Today

Monday, June 2nd, 2008

You can tell that the word “natural” has no legal meaning because it’s used so frequently in advertising. Think about the old Velveeta jingle:

“… seven natural cheeses are better than one!”

There’s no such thing as a “natural cheese” in the strict sense. Cheese is a man-made food product and does not result from any natural process.