NNDB’s Not a Database

My latest project is called NNDB.

I’ve worked with databases for quite a long time now, and for a while I’ve been thinking about how they work under the hood. I know very little about it, but I thought I could learn a bit by trying to implement something similar myself.

I’m interested in how queries work against joined tables, how to implement indices and so on.

I’ve also been feeling that I want to do some C++ as an open source project. I do it all day at work, and for some problems it feels like the right tool for the job.

NNDB is sort-of like an in-memory database, but it works with C++ types for its columns, instead of a fixed set like varchar, int etc. You can put your own value-typed classes in the columns, and all values are type-checked at compile time.

It’s always struck me as strange that with a traditional code+SQL setup you have to keep your SQL in sync with your code manually. Of course, there are lots of trendy Object-Relational-Mapping thingies that solve that problem, but I felt it could be approached from another direction: instead of generating code to match your data, or generating SQL to match your code, why not specify your data structure in code?

In NNDB you define a table something like this:

typedef nndb::Values< unsigned long, std::string, std::string, MyDate >
    PersonValues;

class PersonTable : public nndb::Table
{
public:
    enum Columns
    {
        id,
        first_name,
        last_name,
        date_of_birth
    };
};

Actually, defining your own class is unnecessary, but it’s nice to have an enum to name your columns, and making a class gives you a nice place to put it.

To insert a row you do something like this:

PersonTable person_table;
person_table.Insert( PersonValues( 0,
    "Andy", "Balaam", MyDate( 12000000 ) ) );

You can do simple queries with WHERE and ORDER BY clauses, and I’m working on indexes.

After that will come JOINs, and anything else that takes my fancy.

I don’t anticipate NNDB being useful to anyone – it’s really for me to understand why things are as they are in the world of databases. However, you never know – it may turn out to be a fast and convenient way to store data in the C++ world. I think some of the applications that use databases don’t really need the kind of concurrent multi-user network-accessible features they have, but really just want to search, join and store reliably, and NNDB might one day grow into something that can find a niche.

To explore more, check out the complete example.

Diffident 0.3

My original plan for Diffident, the side-by-side diff viewer and editor that works in a terminal, was to implement basic editing capabilities before making another release.

Of course, that turned out to be quite ambitious. It involves essentially implementing a full text editor, which is not really what I want to do. I may actually implement a “jump out to $EDITOR” option before the basic text editing facilities.

What I have implemented for this release is the ability to add and remove lines, and copy lines from one side to the other. For my personal use, this covers about 90% of cases, so I think it’s worthy of a release.

There is no undo/redo as yet, but the framework for that is in place, so I may make another release sometime soonish that is just for that.

So the dream of a diff viewer and editor is starting to come true…

CBeebies and other channels not working with mplayer

It turns out the scan command from the linuxtv-dvb-apps package (on Ubuntu Hardy Heron, anyway) isn’t writing the correct channels.conf, and this makes some channels not work for me, including CBeebies, CBBC Channel and CITV.

The fix is to do as this person did: http://ubuntuforums.org/showthread.php?t=686829.

Basically, the kaffeine TV viewer scans the channels fine so you can manually copy the values you need from its config file.

The incorrect channels have “0:0” as the second-last and third-last numbers in their row in ~/.mplayer/channels.conf .

Those two zeros should be replaced by the first two numbers you find in the row for this channel in ~/.kde/share/apps/kaffeine/channels.dvb . You can ignore the numbers in brackets in this file.

Firefox keyword search for finding C++ keywords

I often want to search the SGI C++ reference for a keyword. The best way I have found to jump straight to the page I want is to use Google’s “I’m Feeling Lucky” search limited to searching within sgi.com.

You can create a Firefox keyword search to allow you to do this quickly from the location bar. Now I just type Ctrl-L then e.g. “c vector” to jump straight to the page about std::vector.

To do this, make a bookmark (to anything) and then right-click it in the Bookmarks menu and choose Properties. Edit it to look like this:

Firefox C++ search keyword bookmark

The Location field is set to http://www.google.com/search?as_q=%s&as_sitesearch=sgi.com&btnI=1, and the Keyword field is just c.

This post was largely for my own benefit to remember this next time I need to set it up, but I thought it might be useful to others as the information about how to set these searches up is not easy to find.

If you want to go to a google search results page, instead of jumping to the “I’m Feeling Lucky” result, remove the &btnI=1 part.

Flaws in the software patents system

Note: I am in favour of patents on inventions.

I believe the current software patents system has a number of flaws (in decreasing order of importance to me):

  1. They attempt to close off the use of knowledge rather than open it up. If we were not filing patents for our work, we could be writing papers or books to share that knowledge. What would have happened if the Gang of Four had filed patent applications instead of writing Design Patterns?
  2. They can verge on the dishonest. Describing most software development work as “novel” and “non-obvious” is simply incorrect. There is a huge community of software developers, and the idea that none of them would find what I am doing “obvious” beggars belief.
  3. They are a tool that big companies can use to squash small companies. Small companies can’t afford to develop a large defensive patent portfolio. Patents don’t even need to be valid or high-quality: if there are enough of them, a company that can afford a lot of lawyers can destroy one that can’t.
  4. They are a tool that big companies can use to squash open source projects. Many open source projects have no money at all. If a large company doesn’t like some project, they can simply sue for patent infringement (even for patents that are blatantly irrelevant) and the project will be toast.

So I don’t want to be involved in patent applications at my work, even though my employer is keen on patents.

I am now considering how I should act on this opinion. I don’t want to screw my colleagues but I think I want to refuse to be a part of any patent applications as far as I can do that without screwing them.