Archives for the month of: September, 2007

I now have a comfortable experience dealing with broken package installations on KUbuntu, especially in the light of my recent Gutsy upgrade. So I’ve assembled a small list of simple commands that can save your life (and saved a lot of my time more than once). Those should work just as well on Ubuntu.
The first one is THE magic command. Like any magic, it’s not for everyone to see and doesn’t belong to the graphical world of adept updates. It’s closer to the core but simple and effective nonetheless. So next time adept craps on you saying an upgrade has been aborted right in the middle of it because it could potentially corrupt your package database and leaves you with only half of the packages installed (which might not corrupt your database but is very likely to break your system), try this baby:

sudo dpkg –configure –pending

It works everytime. Almost. Because sometimes the package itself is completely messed up (say adept felt like downloading it right when it restarted the network for example) and dpkg will list it as in error. What you need then is:

sudo dpkg -f install

The ‘-f’ is not for force but for fix, which makes you feel more secure. Like somehow a nice developer felt your state of misery in front of a completely broken system and gave some of his time to save a lot of yours. Thanks man.

Once everything is fixed, you’re ready to give that update another try. I now tend to prefer the command line version as it always works, even if X11 or KDE are completely upside down:

apt-get update
apt-get upgrade

Now that you know all there is to know to restore your system I’m going to tell you how to increase chaos and upgrade automatically to KUbuntu Gutsy. If you like to be close to the metal you can also directly edit your sources to use gutsy repositories but I think the automated update goes through some additional healthy cleaning. It’s beta stuff at the moment so be warned (as far as I can tell, Bluetooth has been broken this morning):

kdesu “adept_manager –version-upgrade”

One last thing: when I upgraded, one of the packages needed to restart a few services. I clicked on yes a bit too quickly (mea culpa). In the list of the services was KDM. The KDE desktop manager. Which caused KDE to restart. Killing the upgrade halfway through. Leaving me in a world of pain. Well, woud have without the help of dpkg. So check those little dialogs very well.

The programming world is all riled up, there are too many controversies and fights going on all at the same time. The two main protagonists are “the Ruby people” and “the Java people” with some Erlang or Javascript thrown in the middle. Although these two groups have a lot in common (be it only because many Ruby hackers are ex Java hackers), the critics are still far too vehement. Something is shifting. The language war is back and it’s strong.

In the middle of all this maelstrom, I’d like to call for some peace and reason. Keep that nasty comment for yourself or give it a couple of days to smoothen the edges. Use your heart to understand the others’ feelings and use reason to advance sensible arguments. We’re all friends here, we’re all family. So much bile is bad for karma and bad for yourself.


Picture from Vljay Pandey. 

Compare to Britney and tell me what good the industry did for Music.

Update: during the night, videos of Michael singing Billie Jean at the Motown have been removed. Shame, shame, shame…

In my last post about not-really-closures in Java I demonstrated the usage of inner classes to simulate a closure. I say simulate because those aren’t real closures. Did you spot why? Well, basically a closure has access to the local variables surrounding it and does so by reference. By forcing you to declare everything as final, this semantic is lost in Java. Effectively with real closures, if you change the value of the local variables after the closure has been constructed, it should impact the closure which is not true in Java. And we’ll see that its very easy to demonstrate this behavior in Javascript.

But I have to confess something. The whole point of my little illustration wasn’t really to pinpoint what makes building a real closure in Java impossible. It was more to force you to read the code and get into the details so that you could realize how bad it actually looks. You have to come up with some sort of unspoken contract (the interface) that will actually wrap what you’re interested in, build an either completely typed and static or completely untyped and pointless method signature, play with final variables and write a hell of a lot of boilerplate code.

So let’s see what’s possible today in other languages. Ruby:

addition = lambda { |a,b| a+b }
additions = (0..9).map { |m| lambda { |n| addition[m, n] } }
additions.each { |add| puts add[2] }

Feels better? At least it looks much better to me. Just for keeping an open mind, in Lua:

function addbuilder(x)
return function(y)
return x + y
additions = {}
for m=0,9 do additions[m] = addbuilder(m) end

for n,add in ipairs(additions) do print(add(2)) end

This demonstrates the implementation of a function that builds a closure for you. We’ll see the same pattern in Javascript but before I want you to have a look at what would be a more immediate Javascript implementation:

var addition = function(a,b) { return a+b };
var additions = [];
for (var m = 0; m < 10; m++) {
additions[m] = function(u) { return addition(m, u); };

What do you think, would that work? Take a minute and read it carefully. Because actually it doesn’t work. All the closures will produce the same result corresponding to m having a value of 10. Why? In Javascript, the variable m will be created only once, you won’t get a brand new one at each iteration, which means that the same m will have for value 0, 1, 2, …, 10. As I said earlier, in a real closure, variables are used by reference so all closures reference m and when they’re all created, m equals 10.

So for a better implementation, we’ll use the same technique we used in Lua and introduce a function to build our closures:

function addBuilder(a) { return function(b) { return a + b; } }
var additions = [];
for (var m = 0; m < 10; m++) {
additions[m] = addBuilder(m);
for (var n = 0, add; add = additions[n]; n++) {

As you probably know there are several propositions on the work to introduce first class functions and better closure support in Java, although given what already exists elsewhere and the associated elegance, I’m not sure this will happen fast enough (or happen at all).

Two interesting bits of news this week. The first comes from a music artist, Trent Raznor, the singer of Nine Inch Nails. He recently asked his fans to go and download all their music, including their last album, Year Zero, instead of buying it. What apparently pissed him off is the price of their albums in store. From a recent interview:

It’s a very odd time to be a musician on a major label, because there’s so much resentment towards the record industry that it’s hard to position yourself in a place with the fans where you don’t look like a greedy asshole.

I steal music too, I’m not gonna say I don’t. But it’s tough not to resent people for doing it when you’re the guy making the music, that would like to reap a benefit from that. On the other hand, you got record labels that are doing everything they can to piss people off and rip them off. I created a little issue down here because the first thing I did when I got to Sydney is I walk into HMV, the week the record’s out, and I see it on the rack with a bunch of other releases. And every release I see: $21.99, $22.99, $24.99. And ours doesn’t have a sticker on it. I look close and ‘Oh, it’s $34.99’. So I walk over to see our live DVD Beside You in Time, and I see that it’s also priced six, seven, eight dollars more than every other disc on there. And I can’t figure out why that would be.

Well, in Brisbane I end up meeting and greeting some record label people, who are pleasant enough, and one of them is a sales guy, so I say “Why is this the case?”.

“Basically it’s because we know you’ve got a core audience that’s gonna buy whatever we put out, so we can charge more for that. It’s the pop stuff we have to discount to get people to buy it. True fans will pay whatever”. And I just said “That’s the most insulting thing I’ve heard. I’ve garnered a core audience that you feel it’s OK to rip off? F— you’. That’s also why you don’t see any label people here, ‘cos I said ‘F— you people. Stay out of my f—ing show. If you wanna come, pay the ticket like anyone else. F— you guys”.

I think I’d be pissed too.

Another tidbits shows an even dirtier side of the industry. A company named Media Defender specializes in tracking copyrighted albums and movies downloads and tries to sell protection to the biggies. They’ve first been outed as being the ones behind Miivi, a fake free Torrent download site. They were basically using their BitTorrent tracker to get your IP and then had some convenient ties with the New York Attorney’s general office. They went in stealth mode for a few weeks and then just started their activity again with a different name.

Problem is: they’ve been hacked. And it’s not pretty. There’s 700Mb of e-mails now being mirrored all over the place on several real BitTorrent trackers. And there’s a lot of dirt in there, like their contract with Universal Music, their basic pricing, employees salaries and SSN and exchanges with the New York Attorney’s general office. I encourage you to read the whole story.

Why the following Java code, while being a simple currying example, doesn’t really produces closures?

public class ClosureTest {

public UnaryOperation[] additionCurries(int qty) {
UnaryOperation[] curries = new UnaryOperation[10];
for (Integer m=0; m < qty; m++) {
final Integer mCopy = m;
curries[m] = new UnaryOperation() {
public Integer apply(Integer val) {
// Times 2 then add
Integer mCopyCopy = mCopy;
mCopyCopy = mCopyCopy * 2;
return baseAdd().add(mCopyCopy, val);
return curries;

public BinaryAddition baseAdd() {
return new BinaryAddition() {
public Integer add(Integer val1, Integer val2) {
return val1 + val2;

public interface BinaryAddition {
Integer add(Integer val1, Integer val2);
public interface UnaryOperation {
Integer apply(Integer val);

public static void main(String[] args) {
ClosureTest ctest = new ClosureTest();
UnaryOperation[] additions = ctest.additionCurries(10);
for (UnaryOperation addition : additions) {
System.out.println("5: " + addition.apply(5));
System.out.println("2: " + addition.apply(2));

It's really as close as you can get in Java, but there's still a problem (not demonstrated by this code to complicate things a bit) if you want a real closure.

From a discussion with Alex and Assaf.


Get every new post delivered to your Inbox.