Friday, September 19, 2008

Listening to music and last.fm

Some time ago Anders created a last.fm group for YayArt. Anders showed me how Rhythmbox can integrate with last.fm, reporting in what I'm listening to. So I ended up creating a profile.

At first I find last.fm pretty confusing and leave it at that. A couple of days pass where I play music from my personal collection with Rhythmbox. Then I visit last.fm again. Behold, now it has lots of interesting suggestions. I just click "Play your recommendations" and I get a pretty varied assortment of music. You can control the stream to some degree by either hitting love or ban to what you're listening to.

There are some minor glitches, e.g. I yesterday loved too many film music pieces so it was getting a bit stuck on that kind of music until I started banning some of the pieces, but overall it's working incredibly well.

An interesting side effect is that you can listen to people's music taste. Now if I only knew someone on last.fm whose music taste I would like to listen to... My profile is here in case you want to listen to mine.

Tuesday, September 16, 2008

The role of culture - and what's an object?

I had an interesting thought today. Why do you eat of plates? Our dining table is covered by a fine oilcloth, why don't we eat of that?

The plain answer, I think, is that we've been taught when we were young to use plates, to the point that it even seems unhygienic not to do so. Imagine a dinner with meat, potatoes and a batch of sticky sauce on your dining table.

Image by ayalan

If you're looking for deeper reasons for why one eats of plates it's probably easy to find out. Just have a dinner directly on your table. I suspect the reasons have something to do with the difficulty of cleaning up afterwards and sharp knives and scratches in the surface.

Pottery is a pretty old technology. The point is that it's part of our culture, we never think about it, we just do it. But it's one of the million of things that make up the great technological advancements civilisation has made over the past centuries. If we weren't able to absorb them, if we had to think about all of them, we would never have gotten anywhere.

A similar thing goes on in software. With a programming language you can build anything you can think of, provided you have the hardware to run it on. But still it takes time to invent new things. Old things have to be absorbed into our culture before we can move on, otherwise the leap is too great.

Of course behaviours that once have been embedded might stop making sense as the environment changes, unnoticed. When you dig into it the reasons stop being reasonable. I think you'll find that traditions and rituals provide a rich source of examples of this phenomenon - it made sense to those who concocted it, but 50 years later it's really silly when you think about it. Of course, that might not stop you from enjoying it.

Image by Thomas Hawk

In any case, I think it's sometimes interesting to turn things we take for granted upside-down. Today I've been thinking about the corner stone of object-oriented programming. Let's be pragmatic. What's an object?

You might think of attributes and methods. My take on it is that it depends.

In some types of code, it's a very useful modeling utility.

For instance, just think of the string class in your favourite programming language. It encapsulates most of the stuff you'd want to do with a string in a neat little package you can easily instantiate as many of as you like. If you've ever tried the horror that is the built-in string handling in the C standard library (not to pick on it, it was probably fine for its time), you'll really appreciate that. You might miss the occasional method or two, but still, it's very useful and easy to understand.

Library code is full of neat little packages like this. Dynamic arrays, linked lists, HTTP handling, database connections, widgets in a graphical toolkit.

As you go to application code, the answer is in many cases less clear cut. To a certain extent, this is perhaps because the concepts are less understood or perhaps just less well-defined.

In my applications I find that I have objects that are more or less just data (plain old data, PODs as they call them in C++ lingo) and objects that aren't really objects that I instantiate, let do a well-defined job and then throw away, but more of the sort of puppeteers or glue. These are all objects that give me head-aches. I also find some objects that are like the library objects, neat little packages. These are usually a great relief.

The first type of objects, typical application objects, are troublesome because they go against the culture of object-oriented programming. Which says that you shall divide your code into neat little interacting packages with methods and encapsulated attributes, instantiated and used dynamically.

But if we step back, then what's the purpose of objects? As I see it, it's a way of organising code. Think of it as a hierarchy. At the lowest level, you have the individual lines of code. We organise them into functions which let us deal with perhaps 10-100 times the amount of code, still maintaining an overview, like the headlines in a newspaper that groups the thousands of lines of text into articles.

Image by jurvetson

As a program grows, you need another level, one that will give you 10-100 more code without losing the grip of the program. This is plain hierarchy theory. Look at the folders on your computer for a prime example. An object is one such next level, one that is more flexible out of the box than traditional function library modules because it has state.

However, just because you need another level, it doesn't mean that the code will fit well into the object-oriented thinking of a neat little package where the data is encapsulated inside. I personally think it's impossible in many applications; otherwise it's going to take a lot of hard thinking, and I mean really a lot, because I have often wasted hours trying to find a way out of my crippled semi-objects.

It is true for the plain old data structures. In many cases, you just need to group a set of attributes under a name without the functionality making use of the attributes logically or even illogically belonging to the grouping. So just put them in, recognising this as a case where the object thinking is useful but not a 100% fit.

If you're writing getters and setters for this kind of stuff, you're wasting your time serving the culture of object-oriented programming as it was taught to you.

The same goes for glue code. It may organise the code better to put it inside an object. If so, go for it even if you're never going to do typical object stuff with it.

In any case, as I see it the goal here is a well-organised program. A well-organised program is obviously easier to understand, and thus easier to work with, extend, fix bugs in, etc. Think about that and forget culture next time your wrestle with program design and nothing seems right.

Sunday, September 14, 2008

Weird web troubles

No, I'm not dead yet. I have even been doing some of the maintainer tasks for Flot I have neglected the past months.

One of the new things in Flot is support for hovering/clicking with the mouse on the points. I was spending some time yesterday adding highlights so that Flot can show which point you're pointing the mouse at.


I got to the point that I was ready to performance test it, on my trusty old Pentium 3 950 MHz laptop. It felt a bit slow. Surprisingly, the profile from Firebug indicated that the slow function was the jQuery function offset().

I use it to compute where a mouse event is inside the plotting canvas - for some reason computing this offset separately is the only reliable way to know where the mouse is inside the element where the event happened because you only get the global coordinates reliably in the event. You would have thought local coordinates was a natural thing to standardize and every browser support, but no.

Anyway, offset() walks up the DOM tree, computing offsets along the way. And it was taking 25 ms per invocation on average! That's just ridiculous.

The funny thing is that I was meanwhile updating my system, apparently also updating Firefox from 2.x to 3.0.1. So when I boot up today with a couple of ideas for working around the slow offset function, it's now 4 ms on average. That's still far too much for querying a simple DOM tree, but it's not a show stopper anymore.

I think the lesson here is that as soon as you do exotic things in the browser, things that are not really about browsing HTML pages, you get bitten by weird bugs. But the state of affairs is improving.


Pssst. We're having a sale on YayArt. I have it from a reliable source that it's going to end soon.

Wednesday, April 30, 2008

The way of nature

I was helping my father put up new boards for the roof of my parent's house today. The old one was, well, old and rotten. It was the last remains covering the gutter on the north side of the house, we've already replaced the boards on the other sides of the house (got quite a thrill out of the top ones on a wobbly aluminium scaffold 8 meters above ground).


Anyways, as we've done about half of the boards and reach the far end of the house, a female blackbird starts examining the wooden box around the gutter carefully at the other end, apparently interesting in using it for a new home. A few moments later the male blackbird, maybe its mate, does the same while we stand there, hammering boards in a few meters away.

Leave things alone a few minutes and life around you starts occupying the good spots. Nature or perhaps rather evolution is wasteful with life, but certainly not with space.

I sometimes wonder how fast a city would disappear if all humans were all suddenly extinct by a new plague-like disease.

Thursday, April 17, 2008

YayArt is up!

So it finally happened, we launched YayArt! It's a community-based approach to new digital art for the people (real prints).

That's all. I'm wasted now. :-)

Friday, March 7, 2008

Flot 0.4 released!

New version of Flot is out. See the changes.

The date/time support has finalled arrived and there's support for coloring background areas. For instance, you might use this to plot the visitors to the Flot homepage. There's also support for segmented lines. Plus a long list of bug fixes and tweaks.

For the next release, I'll probably be focusing on adding more interactive features. There are some patches floating on the mailing list I need to take a look at.

I also think it would be a good idea with a hand-holding tutorial that for people who are not accustomed to Javascript plotting. I have something in the works, more about that later.

Favourite Linux bug of all times

Here's the story about my favourite Linux bug: the thrashing hell syndrome.

To reproduce it you need to have swap activated and a run-away process. Traditionally, for the latter Netscape Navigator was great, in these days it might happen with Firefox with Flash or Monodevelop. Or if you're developing something and accidentally make an eternal loop that allocates memory.

What will happen is that the system quickly slows down. You'll have some seconds to react to kill the process. If you're too slow, the graphical interface locks up and you're toast while the machine enters thrashing hell. You can usually get to a terminal and even enter username and password, but it locks up again before the shell is running. Probably because you can't spawn a new process when in thrashing hell.

The condition will last for anywhere between a couple of minutes and more than half an hour. Unless you power off the machine, there's nothing you can do. At all. Other than to stare at a frozen screen while the machine entertains itself.

At some point an out-of-memory killer was introduced in an attempt, I believe, to mitigate this problem. Its job was to kill a process to free up memory in memory-tight situations. Here's a hilarious analogy by Andries Brouwer. I suspect Netscape was the main cause, although I might be wrong, I've never been close to kernel development anyway.

Anyway, that was long time ago.

Fast forward to the introduction of Ubuntu, the really easy-to-use GNU/Linux. I should warn you that I'm going to do some bashing of Ubuntu now, which is not really fair since Ubuntu is pretty cool.

When I first got into thrashing hell on a Ubuntu system, I didn't believe it had happened. I thought the OOM killer should have saved me, but apparently not. Probably it'll only kick in when all of the swap is used. But hey, Ubuntu is for the masses, right? The system should have protected me. That's what I naively thought.

So I filed a Ubuntu bug report on the kernel. I hoped that a couple of the knowledgeable people who are working on Ubuntu would fix this old problem in a snap.

Which didn't happen. The bug wasn't accepted. As far as I can tell because the guy in the other end thought the process limiting support in the kernel is advanced enough to take care of the problem. I wasn't sure whether he was right. But I filed a new bug report with the hope that someone else would see the vision.

That's over two years ago. So far no progress. Which is not what I'd hoped, because it really puts the system in a bad light. If this happened to an average user, that person would instantly conclude that Ubuntu/Linux just crashed.

But it's sort of fine, because it's open source etc. etc. and the people in the other end are free to spend their time as they like.

Then today there was an update. Cool! I thought. Until I found out that it's just a drone reply. Even a particularly annoying one, apparently it's not good enough to report a bug on the latest release since the problem might theoretically be fixed in the next alpha. The bug has already been auto-closed once because if noone's interested then the report must be invalid.

So noone wants to listen. That makes me think this will continue to be my favourite Linux bug for many more years to come.


PS: My favourite recent Windows bug is probably the one where Windows interprets all mouse clicks as right-button clicks.