Category Archives: Programming

The worst decision in the design of the Internet

The Internet is a frankly incredible design. The IP protocol, which is at its heart, is technology from 1974. TCP, which implements connections on top of IP’s packet delivery, is from the same year. Forty-two years on, both are essentially unchanged. Even DNS, the domain-name service, dates back to 1983, and is going strong 33 years in with only minor tweaks.

The only big change in this time has been the slooow migration (still in its early stages really) from IPv4 to IPv6 — something that has proven necessary as the Internet has been so wildly more successful and popular than anyone anticipated, and the 32-bit-wide host addresses are running out. But in the scheme of things, this is a minor tweak. We’re running the Internet on 1970s technology, not due to sloth, but because it’s good.


Continue reading

A coding confession

I just found this code in one of my source files:

for (HashMap.Entry<String, Void> e2: map.entrySet()) {
  if (eventName.equals(e2.getKey())) {
    m.handle(eventName, data);

Yes. I was iterating through the keys in a HashMap to find out whether the one I wanted was there. But the whole point of a HashMap is that looking up a key is an O(1) operation.

What I should have written is:

if (map.containsKey(eventName)) {
  m.handle(eventName, data);

The moral of the story: I can be really, really dumb. (But hey, at least my code worked!)

Dependency injection demystified

At the moment, most of my actual coding work is in Java — which is a novelty for me, as it’s not a language that I am naturally inclined to like. But as I’m coming to grips with it, I’m finding that Java in 2015 is a rather more pleasant language than the one I wrote a CQL parser in back in 2002. The main problem with it is the culture, and in particular the huge vocabulary of patterns, which takes a long time to learn.


So here is today’s brief lesson, which is on dependency injection. Continue reading

New free software for drawing diagrams of vertebral columns

I already blogged about this over on Sauropod Vertebra Picture of the Week, but since it’s a software release, I figure I ought to mention it on my programming blog, too!


Matt Wedel’s and my 2013 paper on bifurcation in the neural spines of sauropods included the figure above, which shows in schematic form what we know about split spines in the vertebral columns of various specimens. Rather than draw this by hand, I wrote a program to generate it from a simple textual description. Continue reading

JavaScript hashes that inherit from a parent

For a JavaScript program I’m working on, I want to have hashes that can inherit values from a parent. Specifically, I have many widgets, each with a (usually small) hash of configuration parameters; when I access such a parameter and it’s not defined in the widget I want to get the value from the configuration of the team that the widget belongs to; and when that’s not defined I want it to get the value from the global configuration.


Continue reading

… Or maybe they’re doing web-site registration completely right

A couple of weeks ago, I wrote that DeviantArt are getting web-site registration completely wrong by asking for the email address (which you can see as you type it) to be repeated, but not requiring confirmation of the password (which you can’t see).


A lot of people in the comments (both here and at Hacker News) pointed out that I was wrong.

Continue reading

Inclusive and Exclusive OR in informal speech

As good computer scientists, we know that there are two kinds of OR.

An inclusive OR, which is what we nearly always need in programming, is true if either of its branches is true: “exit this loop if we’ve processed 50 items OR there are none left to process.”

An exclusive OR is true if exactly one if its branches is true, but not if both are. “If player 1 is attacking player 2 OR player 2 is attacking player 1 (but not both) then inflict damage.” [This is a contrived example: that’s because it’s hard to think of non-contrived examples — they hardly ever come up in real programs.]


When we use “or” in informal speech, we nearly always mean exclusive or. If I tell you I’m going to the cinema to see Skyfall on Wednesday or Thursday, you understand that I will go on one day or the other, but not both. If I ask you what you want to drink and you say Abbot Ale or Ruddles County, you’d be surprised (but maybe not disappointed) if I brought you two pints.

Continue reading