how the dutch destroyed biking

October 26th, 2008

The Netherlands, a paradise for bikers. Twelve million bikes on seventeen thousand kilometers of dedicated bike paths. And a country so flat that you'll never be pushing your bike uphill because the hill is too steep - there is no hill. There's basically no corner of the country that isn't accessible to a biker, the place sometimes looks like a bike track with a country attached to it.

And yet, something is wrong. Very wrong.

You might think "Hey the Dutch are nuts about biking, I bet they have great bikes over there!". You'd be wrong. The bikes in use in this country are something out of an old Soviet factory. Single speed, pedal brake, black paint (or painted a bright color to conceal rampant corrosion), with a regular chain for locking. Often you can hear them coming, wheels spinning unevenly on the axle because the rims are slightly bent, lights fastened poorly and about to fall off, crank screeching against the panel that conceals the chain. Not surprisingly, bike repair is a thriving business in this country, repair shops are everywhere.

In fact, these old bikes are so dominant that it's difficult to find a bike that isn't one of these historical exhibits. Furthermore, bike theft is so widespread that people don't even want to own anything worth stealing. (A guy once told me he loses roughly one bike per year to theft.) Dutch people love to joke that the lock usually is worth more than the bike is. That's true, I just don't see why that is supposed to be funny. I wouldn't want to live in a house where the lock on the front door is worth more than the house itself.

Then there are the bike lanes. Yes, they are dedicated to bikes, and yes they are separate from motorized traffic. What you probably don't expect, however, is just how boring it is to ride on them. They are completely flat, they have their own traffic lights, and even indicators for traffic going in different directions. It's no wonder bikes don't have any gears, there's no way you could build up any speed before you have to stop at the next light. It is the experience of urban biking with the added bureaucracy of driving a car

Not only that, traffic regulations for bikers not only exist, they are enforced. That means you have tax collecting traffic cops just waiting to write you a ticket for any number of trivialities, like riding on the sidewalk (even when it's void of pedestrians), riding a light when there's no traffic, or riding without lights. Lights which, of course, will be stolen unless you obsessively remove them every time you park the bike. (Unless the whole bike gets stolen instead.) It's almost a wonder you don't have to fill in a form every time.

Then there is the terrain. When you're not biking in a town, which is about as much fun as driving a car in heavy traffic, you will find yourself somewhere on the grid of bike lanes that connect towns, out in the great outdoors. What fun! Well, at least until you realize that every slice of the country looks almost exactly the same, and the only thing there is to see anywhere is grasslands with canals crossing them. If you're lucky you might spot a forest, but they are very uncommon. And it's completely flat, so not only is there nothing to see here, you're well aware of the fact that 10km down the road there's also nothing. Scenery wise, this country is as close as you get to a desert.

The Dutch response to all of this? "Biking was never supposed to be fun, it's transport." Well, there you have it, it doesn't get more depressing than that. "Music an art form? We just needed a beat the soldiers could march to."

Shooter: could have been decent

October 25th, 2008

A conspiracy thriller with a redneck in the lead. An unusual angle, but worth a try. The story is he was a sniper in the army, then he got called in for a very special job with the FBI: to plan the assassination of the president cause they believed someone else was going to do it and they wanted him to tell them how it could be done.

Not a great story, but not a bad one either, there is enough to work with no doubt. But that's kind of where the positives end. Mark Wahlberg in the lead.. not bad frankly, but for a role like this you need an actor who can be sensitive, someone who can express the turmoil that he's going through, and Mark just isn't it, the best he can do is look serious. If you think that is revealing, you're onto something. The big problem with this movie, nay disaster, is casting. The casting is horrendous, to the point that not a single actor is right for his/her role.

There is Danny Glover, so admired from the Lethal Weapon epic. For some reason he doesn't even have a voice to speak with, barely producing the words. But he's one of the better ones. The eager detective Nick Memphis who just started at the FBI. Eager yes, but playing a detective like you would a bartender, no feel for it. Swagger's female friend looks like a contestant for Miss America, dolled up like she's going shopping, lives on a farm. Again, no personal drama that anyone would buy. And so it goes, the standard FBI/police war room personnel in a movie like this, all of them misfits, badly cast. Same goes for the bad guys.

I felt the first half of the movie was going somewhere, but the ending is crying out for a rewrite. When you're doing a plot like this you can win the viewer over by building up to something. It's a matter of trust, you tell a story that captures the viewer's interest, and based on that you make a promise to deliver something later on. I'll agree to hold my judgment and go along with you. That's why you have to deliver at the end, you can't just walk out, or the trust is broken. A feeling of betrayal ensues.

A good director could have taken this plot somewhere, maybe even with the ending as it is. But the casting is unbelievably bad.

Little Brother

October 20th, 2008

Cory Doctorow published this book in 2008, both online freely and in dead tree format. It's a (mildly) futuristic story in a time when a lot of privacy battles have already been lost. Security cameras in school tracking people, cameras on the streets, tracking people through rfids in their cars and their mass transit tickets. Then a terrorist attack occurs. National security is elevated immensely.

Doctorow is doing two things. He is setting the stage for a thorough tutorial on how to use anonymizing technologies and he keeps elevating the plot to keep introducing new methods and ideas. As a technologist connoseur he isn't forced to make up things that aren't realistic and embarrass himself. In fact, he doesn't seem tempted to invent anything, which is a bit odd for a futuristic story, he's basing the account on technologies we already know today. (Although tunneling a video stream over DNS is a bit far fetched on our current bandwidth.)

Secondly, he's trying to educate about the threats that we see today and the already existing encroachment on civil liberties. Not in a preachy way, but it's part of the message. He will digress occasionally to tell a story from history. He does well to integrate this into a captivating story.

Although it seems similar at first, it isn't Fleming and it isn't Ludlum, in a high school story. Little Brother is about normal people who face predictable consequences, no miracles included. Doctorow isn't trying to craft characters who seem impossible, he likes it down to earth. I have a hunch that sections of it are auto biographical as well.

In closing, I tip my hat to Jürgen Geuter, who turned me onto Doctorow's other 2008 book Content a few weeks ago, a collection of essays about security, privacy, and freedom.

update on undvd packages

October 9th, 2008

One of the benefits of coding in a scripting language is the ability to easily move the code around and it runs everywhere. undvd is easy to install, you just extract the source and it's ready to go. Or, if you want to install it globally on the system, just run make install and you're set.

But undvd depends on a bunch of other tools, so what you really want is to let your package manager deal with satisfying the dependencies, and let you upgrade easily when a new version comes out.

Where can I find undvd?

I package undvd in three flavors myself: Gentoo, Fedora and Ubuntu. I run Gentoo and Ubuntu on my boxen, so those are the most well tested. In addition, ripdvd's author wedge does the honors for Slackware. :cool:

But there are some unofficial packages out there as well, so when you add it all up undvd is pretty well supported at this point.

Making friends with posix

Recently, a user expressed an interest in running undvd on a Mac, which is a whole new angle. I guess it never occurred to me that someone would use undvd outside linux, but why not. The recent switch to perl has obsoleted the many external tools that undvd previously relied on, which is a big [if unplanned] step towards portability. I ran some tests that revealed there were still a couple linuxisms left, so I've gotten rid of them now.

undvd-0.7.1 should in principle run on a Posix system with perl-5.8.8. The big thing isn't undvd, it's getting mplayer and the other binaries, cause they have to be built specifically for that platform. And outside linux, there's sometimes no standard package manager, which doesn't help at all.

At the end of the day, there is no escaping the fact that undvd on Posix is a fish out of water (true not only of undvd but probably most free software) - the environment just isn't as well supported as it is in a linux distribution that ships all the tools. There are no packages for any of these, but you can just extract the tarball and run undvd from whatever location.

DesktopBSD 1.6 (FreeBSD Ubuntufied)

It runs (except mencoder can't find x264, so I used xvid). The dvd device is called /dev/cdrom or /dev/acd0. Cloning with dd fails, vobcopy works.

OpenSolaris 2008.05

It runs (except mencoder can't find x264, so I used xvid). I have no idea how the device naming works, but when you put in a cd/dvd it should automount and you can look up the dvd device in the mount table. Packages for mplayer are available from Blastwave. Playback with mplayer worked, encoding segfaulted mencoder.

Mac OS X Leopard

It runs. The dvd device is called something like /dev/rdisk1. Mac people seem to be obsessed with guis, so any builds I could find only had mplayer playback, no encoding. Your best bet is probably MacPorts, modeled loosely on FreeBSD's ports. You'll want to build mplayer with the codecs you want selected as variants (think Gentoo USE flags). Disc cloning doesn't seem to work at all.

To install globally you'll want something like DESTDIR=/opt/local sudo make install.

Cygwin

It runs, and you can get builds of mplayer from the official site. The dvd device is called d: (or some other drive letter). Set PATH=/cygdrive/c/mplayer:$PATH and make sure c:\mplayer doesn't contain both a directory mplayer/ and a binary mplayer.exe, this makes cygwin very confused. On the whole it seems to work quite well, the process even successfully sets the cpu priority (nice).

on Perl

October 7th, 2008

I discovered Perl in the old millennium. I was building websites and I found out that HTML isn't Turing complete. Content and layout was cool, but it didn't really *do* anything. That's when I heard about CGI. I would find Perl scripts on sites that don't even exist anymore, upload them, get the 500 error, stare at the logs, revert any changes I had made, and try again. It wasn't sophisticated, and I wasn't even writing any code, all I wanted was to get the damn thing to work. The fact that Perl was the language made no difference to or fro. It was packed with frustration, though.

The principle of surprise

I've written code in Bash, C, C++, Haskell, Java, Pascal, PHP, Python, Ruby. So I feel like I've been around the block a few times, as far as choosing a language. And yet, Perl leaves me bewildered. One of the pillars of Ruby is something called "the principle of least surprise". What it means is that when you're not sure how to do something in Ruby, and you just do what seems most likely to work, it works. It's a wonderful quality, and it seems to be based on Perl, because Perl is the exact opposite.

Perl smacks horribly of apprenticeship culture. One where the novice is carefully guided through the valley of death, across the bridge over the pit of lava, past the nine-headed monsters, by a veteran monk. Send a tourist out there with a map and he's likely to be sent home in several pieces. Take a look at a common mistakes document and you find an immensity of pitfalls, not just in the language itself, but also from version to version.

This quality isn't merely at the fringes, it permeates the languages as a whole. Take arrays, a fundamental type in any language. Type print @arr and you get LarryWall, the elements of the array printed out. Type print @arr."\n" and you get 2<newline>. Que? Put an array in the context where a scalar is expected and you get the length of the array. Better yet, call a function like this: func(@arr, $arg3). Guess how many arguments the function has? Three. The array has been flattened and concated with $arg3. Yep, auto expanding arrays, ain't it grand? I like automation, but this is too automatic.

It's very common to get an integer where you expect to have a string. One common Perl function is chomp, it removes the trailing whitespace. I was getting an integer until I figured out it's a destructive function. This is another weird quality for a scripting language, you have lots of destructive functions that give integers as return values, as if you're doing syscalls in C.

I was stuck on one problem for hours because the value I was printing never made it to the screen. It turns out it was because of line buffering. So how do you flush the buffer? I looked for a flush function, there isn't one. Nah, you set the variable $|. Should have been obvious, but it wasn't.

Here's another one. Say you set a variable in a config module and read it in a code module. Now you want to rename it, how many places do you have to do that? The answer is four. 1) declaration, 2) use, 3) explicit export in config module with Exporter, 4) explicit import in code module. This is ridiculous.

A bag of hacks

When it comes right down to it, Perl is an amalgamation of hacks into a big, messy package. Granted, many of the syntactic hacks are useful, like qw(). Others are completely incomprehensible, like all the variables called $<nonalpha>. These all mean something: $_, $-, $+, $`, $', all related to regular expressions. $_, though, is used all over Perl to store "the thing you may want to have".

Despite all this syntax, there's none for declaring formal parameters to a function. It's just like Bash, pass in whatever you want, and then you read it out from an array. One common idiom is my ($var1, $var2) = @_. If you only have one variable you might be tempted to drop the parentheses and write my $var = @_, which will give you a fun bug (an integer), because now you're assigning an array to a scalar, not to another array.

Most (modern) languages have set a sane policy on pass-by-value vs pass-by-reference. And there are those with a foot in each camp, making the coder constantly second guess himself (thank you, C++). Perl, predictably, is conflicted about the issue. By and large you pass values around like you're in Bash, but pointers/references exist too. Here's a motivating example.. how do you pass two arrays to a function? Derm. You.. can't. When they come out the other end the arrays have auto-flattened and it's now one big array. So here's how: func(\@arr1, \@arr2). And in the function you say my ($arr1, $arr2) = @_. What the? Bear with me. Now you have two references. To dereference you go: @$arr1[2]. Same goes for %$ (hash) and &$ (func/closure reference). You sort of "wrap" the type being pointed to around the pointer. Needless to say, this syntax debauchery doesn't make code simpler.

It gets better. Perl's support for complex data structures is really... interesting. I was messing with an array of hashes once. And I needed to sort the records by a key in the hash. (Picture a table, click on the column name to sort by it, that sort of thing.) This might sound lame, but it's not obvious how to sort this. I spent hours on google and I found all sorts of examples, averaging about 15 lines. 15 lines to sort an array of hashes? What is this, C? I didn't understand them, I kept looking. Eventually I found an academic looking paper about the issue. It demoed various approaches, concluding with a 4 liner that was supposed to be the best, hurrah! The code is so incredible that I have to show you.

my @sorted =
	map $_->[0] =>
	reverse sort { $a->[1] cmp $b->[1] }
	map [ $_, pack('C1' =>
		$_->{"priority"}) ] => @unsorted;

Let me try to unobfuscate this. There's an array of hashes and we're sorting by the key called "priority", an integer value. In pack, we grab the value of "priority" for that particular hash and make a string of it (wtf). The map just outside pack does this for every hash. So what have we? A list of strings. We now run reverse sort (by decreasing integer value) on this. And the outer map is just a way of saying "take the existing array and replace it with this". I think. I still don't understand the details of this code. But imagine, convert all the keys you want to sort by to a frickin string and sort the strings lexically, then figure out which position every string went into and order the hashes accordingly. It's madness.

(Disclaimer: I was a total Perl noob when I was looking for this code, so maybe I missed something, maybe I explained it wrong.)

Somewhere in this madness someone decided to introduce a little order. It's become a standard for Perl code, you put this verse in your module: use strict. What it does is your code will no longer run (presumably the reason it's not on by default). It adds some static checking, so misspelled variable names no longer fail silently and that sort of thing.

Maddening syntax

Perl not only has syntax for "useful things", it has syntax everywhere. Like in PHP, the $ sign must accompany every variable always. Except if it's an array, then you use my @arr = (elem1, elem2), and my %hash = (key=>"value") for hashes. But then again, when you access and array element you write $arr[1], and same for hashes. So what the heck? You can also declare hashes through a reference, which goes my $data = {key=>"value"}. More syntax, more fun, right? Basically, it's @ for arrays, % for hashes, & for functions, and $ for... everything else.

And, of course, always remember my, because Perl thinks all variables should be global by default (wtf?).

I swear my fingers are more tired from Perl than any other language. There is so much syntax to type. At least it's tolerable when you have vim's tab completion set up. It's not "intelligent", so it doesn't filter out suggestions that don't fit the context, but it's good enough so you never have to type an identifier or keyword twice.

So why Perl?

Despite everything, in the end Perl is not such a horrible language. As the saying goes "you get used to everything", which implies than every language is usable, as you will eventually get used to it. The benchmark, then, should be on how long it takes you. And Perl is awful at first, terrible language to "try stuff out" in. Realize you have to change the type of a variable and because of the silly $/@/% syntax you have to run all around your code to change it. On the other hand, if you know what you need, then it's not as painful. And as I'm finding out, it doesn't take that long to adapt.

The nice thing about Perl is that it's so close to the shell, and a sort of power set of the shell. You have grep built-in, you have regular expressions as native as they get, you have various shell commands included, fast access (not necessarily easy access) to sockets, pipes, all the good stuff. It's nice to have thin wrappers around syscalls, sure as hell beats doing it in C. And heck, I like to break lines with . (concat) when printing strings, and because the ; is required I don't have to stress about it.

Beyond that, Perl has its place in the language ecosystem. Learning Perl is a way to understand Ruby, which is based, in part, on Perl. It's also a way to understand C, which Perl inherits from. That isn't to say using $_ in Ruby is a great idea, but now at least I know what it is when I see it.

And you know the blocks/closures that everyone loves about Ruby? They're from Perl. You can't write them as neatly, it is Perl after all, but I do quite like map { /$device on ([^ ]+)/ } $mount_data;

People obviously have their own criteria for picking a language. I've realized that perhaps the most important thing is how the language lets you manage data (or maybe I'm just saying that because I like Python?). Perl is definitely not a great choice here. It has good string handling, but once you get into multidimensional types (and I haven't even mentioned Perl's "object oriented" features) I run screaming back to Python.

I suppose Perl's chaos can in part be excused on historical grounds. After all, modern languages like Python and Ruby that don't have these problems had the benefit of Perl's example. But then again, Perl isn't the only older language still in use, but it does stand out as the most chaotic.