Feeds:
Posts
Comments

Toys. With each generation, the number of toys per infantile capita is surely increasing. My nephews have so many toys they can barely keep track of them all. I was a relative toy pauper by comparison, but next to my dad, I was as rich as Croesus. In Dad’s childhood, money was scarce and toys were a luxury beyond his reach. But little boys want toys, so human innovation filled the gap – they made their own.

King of the home-made toys was the cotton reel tank, a wind-up automotive device made from a candle, a cotton reel, an elastic band, and two used matchsticks. Once the craft had been passed down from father to son, I too found joy in building and performance tweaking these little beauties. I’d discovered the pleasure of making something, however primitive, with my own hands.

cotton reel tank

In the spirit of the cotton reel tank, I sometimes have a hankering to knock up a little digital toy as a fun micro project. Something of little or no practical use. How about a Magic 8-Ball Twitter bot? A search revealed a handful of such bots already existed, but not one was still functional. Some tweeted their last in August 2010, no doubt victims of the Twitter OAuth Apocalypse. Another unfortunate example replied repeatedly every two minutes to any question, the only way to stop it being to delete the original tweet. A disappointing 8-Ball fail.

Having taken into account all of this prior art, I defined the requirements of my bot thus – it should:

The open source Twitter4J Java library supports OAuth, so no problems there. To ensure the bot only replies once meant persisting the ID of the most recent tweet replied to, for which I used Prevayler. I pass this persisted tweet ID as a parameter when querying the Twitter API (via Twitter4J) for new mentions, so the bot only “sees” each question once.

The maximum wait for a reply is determined by cron config. I scheduled the bot app to run every two minutes, which seems like a reasonable worst-case time to wait for the omniscient wisdom of the 8-Ball gods, plus I’m mindful of Twitter API rate limiting. Responses are read in at runtime from a simple text file populated with the standard 20 8-Ball responses, one of which is selected at random when creating a reply.

wise8ball-tree-falls-in-forest

And that’s about it – a crude toy that was probably more fun to make than it is to play with, although I still get a kick out of asking it stuff once in a while. Take my cotton reel tank for a spin yourself by tweeting a yes/no question to @Wise8Ball; you may be surprised by how profound it can appear.

Interesting question and some good answers:

http://www.quora.com/Why-do-many-software-engineers-not-like-Java

Some beauties in the answer to this question on Quora. “// Fingers crossed!” and “# YOLO!” would probably be a lot less amusing if you were sitting in front of the code scratching (or shaking) your head:

What is the best comment in a source code that you have ever encountered?

Big-O Notation explained nicely on Quora:

Answer by Gayle Laakmann McDowell:

This is a true story.

In 2009, a South African company named The Unlimited grew frustrated by their ISP’s slow internet and made news by comically showing just how bad it is. They “raced” a carrier pigeon against their ISP. The pigeon had a USB stick affixed to its leg and was taught to fly to an office, 50 miles away. Meanwhile, the company transferred this same data over the internet to this same office. The pigeon won — by a long shot.

What a joke this ISP was, right? A BIRD could transfer data faster than them. A bird!

Their internet may or may not have been slow, but this experiment doesn’t say much. No matter how fast or slow your internet is, you can select an amount of data that will allow the internet or a pigeon to win.

Here’s why:

How long does it take a pigeon to fly 50 miles with a 10 GB USB stick attached to its leg? Let’s say it takes about 3 hours. Great.

Now, how long does it take to transfer 10 GB on the internet? Let’s say you have pretty fast internet, and 10 GB only took 30 minutes. Okay, then transfer 100 GB and you know it will take more than 3 hours.

How long does it take that same pigeon to “transfer” 100 GB? Still 3 hours. The pigeon’s transfer speed doesn’t depend on the amount of data. (USB sticks are pretty light but can fit a ton of data.)

So, just like that: the pigeon beat the internet!

The pigeon’s transfer time is constant. The internet’s transfer time is proportional to the amount of data: twice the data will take about twice as much time.

In Big-O time, we’d say that the pigeon takes O(1) time. This means that the time it takes to transfer N gigabytes varies proportionally with 1. That is, it doesn’t vary at all.

The internet’s transfer speed is O(N). This means that the amount of time it takes varies proportionally with N.

Now, what if you had something that was O(N^2)? This would mean that the time varies with the size of N squared.

A real life example of an O(N^2) problem would be the time it takes to paint a square wall of length N (note: N is the length of the wall, not the area of the wall). If I make the edge of my square twice as long, the area of the square wall increases 4x.

Big-O offers an equation to describe how the time of a procedure changes relative to its input. It describes the trend. It does not define exactly how long it takes, as a procedure with a larger big-O time than another procedure could be faster on specific inputs.

Note: If you’ve taken an algorithms class, you might remember that, technically, big-O refers to an upper-bound. Anything that is O(N) could also be said to be O(N^2). To describe the exact runtime, we should be using big-theta.

However, outside of an algorithms class, this distinction has basically been forgotten about. People use big-O when they should really be using big-theta.

What’s the best way to explain big-O notation in laymen’s terms?

I have this tiny app on an Ec2 micro instance. It uses the Twitter API, via the Twitter4J Java client library, to record the number of followers for a given list of Twitter handles. I’ve cronned it to run once a day, so for each of the Twitter accounts I’m interested in, for example my bots, I have a CSV file that tracks the number of followers over time. Simple, crude, and good enough.

A friend asked me if I would do the same for his Twitter account. “No problem”, I said, because, you know, I’m generous like that. Add it to the list, CSV file magically appears the next day, and Bob’s yer uncle. Every once in a while I would email him an up-to-date copy of that file, that analytical masterpiece, that source of valuable “Business Information”, and he’d plot it as a graph in Excel, or whatever it is he does with it.

Keegan's wisdom

This arrangement was fine for a couple of weeks, but it soon became clear it would be better for both of us if he had direct access to his data so we could do away with this bothersome emailing business altogether. So, how to do that? Call me skittish, but I’m not mad keen on granting SSH access to any old Tom, Dick or Harry, personal friend or no. And in any case, I’m sure he’d find SCP a little bit of a faff. How about good old HTTP?

Continue Reading »

Last week I registered my first ever company in the UK – hurrah and huzzah! (That’s not the company name, just the sound of me celebrating). The hardest and most time-consuming part of this operation was coming up with a name. I wanted the root of my company name to fulfil the following deceptively tricky requirements:

  1. It must be unregistered at Companies House in any variation – not only should there be no “XYZ Ltd”, but also no “XYZ Accounting”, “XYZ Blinds”, etc.
  2. The .com domain name must be available
  3. It should be short – ideally one word, so nothing like “Blue Sky Software Consulting”
  4. It should sound good to my ears (I’m going to have to live with it for a while, after all)

Initially I did the same thing most people probably do and tried to rely on my own unprompted creativity. “How hard can it be?”, I thought. “Come to me, company naming muse, I have cakes and PlayStation…”.

Muse reading Louvre CA2220

Continue Reading »

I’m currently reading the excellent Growing Object-Oriented Software, Guided by Tests. Although I have read less than half of it so far, this book has already changed the way I think about Test-Driven Development. It covers a broad range of TDD topics and their intersection with OO, but for now I want to focus on a very small part of this landscape – the naming of unit tests.

Names are important. Class names, method names, variable names – good names inform us, bad names mislead. I’m sure we all know that naming stuff can be tricky. However, a little discipline in choosing names can go a long way to improving the quality of unit tests.

Consider a tiny class I wrote recently while performing the leap year kata:

public class Year {

    public Year(int year) {
        // constructor type stuff
    }

    public boolean isLeapYear() {
        // code to check for leap year
    }
}

I could have made isLeapYear() static, and in fact I have done so in previous attempts. But it isn’t the design choices of the interface to Year that I want to discuss.

Continue Reading »