saturday, 5 february 2011

posted at 09:13

Hmm, I don't write here much anymore. As is the case for lots of people, my blogging has suffered in favour of spewing random crap into Twitter, Facebook and elsewhere. I'm actually doing a lot more stuff via "social" sites in general, so I think a redesign of this site might be necessary soon to bring all that stuff into one place so I don't look dormant to anyone that just follows here.

Anyway. Christmas and holidays have come and gone. I spent a good amount of time on the big idea that I mentioned last time, and got it close to finished, but then in performance tests found that that the naive old-school Ajax implementation I'd done wouldn't scale much past 30 users. Thats unacceptable, so I started to read up WebSockets, Comet and other things to reduce network and processing on a web application. I settled on using Tatsumaki to implement a long-polling version, but that meant a rewrite of much of the server and the client. At this point I was well and truly on holiday and my brain had shut off, so I threw the project on the backburner.

This can be a dangerous thing for me, because I inevitably change my mind and do something else. I started watching Babylon 5, a show I'd somehow missed back in the day. Anyone that's read for a while knows my long infatuation with space games, so of course I started looking around for something spacey to do or play. And last week, I found Pioneer.

Pioneer is a clone of Frontier, the sequel to Elite. I always much preferred it to Elite. I think it was mostly because of the scale - I could fly forever, land on planets, and just bum around in my spaceship. So I grabbed the code, built it and had a play. And I got sold on it quickly because its awesome, but has a giant stack of things that need work still. In the spirit of the new "just do it" style I'm trying to live up to, I decided first that I wanted to hack on it and then started playing and figuring out what I wanted to hack on. After a couple of hours play I found a heap of little bugs and tweaks that needed fixing, and because the main coder is an awesome guy, lots of my stuff has already been merged.

Not much else to write. This is mostly a "here's what I'm up to" kind of post, so now you know. If you like space games do grab Pioneer (and pull my integration branch if you just want to see what I'm doing). Cheers :)

saturday, 13 november 2010

posted at 23:10

Anyone who has spent any time around me knows that I'm something of a dreamer. I think big, and if I get an idea I tend to overthink it to the point where even the thought of starting is completely demotivating. As a result, something I've been thinking about and working on for over ten years has perhaps a thousand lines of code over several rewrites to show for it.

Two articles I've read this week have both challenged me and inspired me to produce something. The first is a blog post by Tom Critchlow describing how he built booklist sharing site in four weeks with no prior programming experience. This is a hugely impressive feat and shows just how much the web has changed in the last few years. It used to be that sites like Geocities existed to make it easy for newcomers to build a website. Now with web frameworks Django and Ruby on Rails and easy-to-use infrastructure like App Engine its easy for newcomers to build a webb application. I've been following Pamela Fox's efforts to bring the Girl Develop It program to Australia. Although its goals are different (bring more women into IT) its recent success reinforces the point: its now easy for people with no prior experience to get into web application development.

The second article is from is from the ever-insightful Rands in Repose on how the recently-released Instagram is so awesome because of everything it doesn't do. I'm not entirely sure of the timespan involved, but the story goes that they've built an amazing mobile photo sharing application and it only took them eight weeks. They did this by remaining completely focused on the core feature set and not allowing any distractions in. Conceptually what they're doing has been done several times before, but by remaining focused they've collected huge amounts of users and standa good chance of beating out the competition.

I found both these stories rather inspiring. I've have my great idea, and I have more experience than many of the people doing these amazing things. It should be easy for me to do all manner of amazing and interesting things, but get mired in details. However I'm now resolved. I've spent much of the day distilling all my plans and dreams and thoughts into one very simple concept and I'm going to have a crack at building something soon. I'm making a huge effort to not overthink it - of course I have some ideas for where it could go, but I'm keeping these as high-level next steps, and not thinking too much about the details.

Unfortunately I don't think I'm going to have much time in the next few weeks to do much, but I'll be taking a proper holiday for four weeks after Christmas and I'd really like to have something to show for it after that.

And no, I'm not telling you the idea yet. Its probably not that amazing or exciting to most people, but its been mine for years and years and not willing to share it until I have something to show for it :)

thursday, 10 december 2009

posted at 11:26

Work is sending me on a Perl Training Australia course this week, so I'm getting to hang out with Paul and Jacinta and get a good refresher on Perl OO. I wouldn't say I needed it, but I've been enjoying the discussion and it never hurts to make sure that your accumulated understanding matches the current reality.

One of the exercises involved a class representing a coin with methods to flip the coin. One of the things we were asked to do at one point was to create an array of coins and do various things to them. My first instinct to create the array was to do this:

my @coins = (Coin->new) x 10;

I was saddened but not surprised to find that this doesn't work. As the following test demonstrates the left hand side is only evaluated once and then just copied, so I ended up with an array containing ten references to the same object:

$ perl -E '$c = 0; @x = ($c++) x 10; say @x'

The best I could come up with is this, which I don't think reads anywhere near as well:

my @coins = map { Coin->new } (1..10);

We briefly discussed whether it would be worth developing a core patch to do something like it, but realistically the only option that preserves a reasonable amount of backward compatibility is to only reevaluate the left side for a very specific set of types, namely code references, giving something like this:

my @coins = (sub { Coin->new }) x 10;

Given that that really doesn't read particularly better than the version using map, and not knowing if anything smarter is possble (and how to do it if it is), and knowing that the core developers aren't particularly keen on new features to existing constructs at the best of times, I've opted to leave it for now but keep my eyes open for things like this.

One part of another exercise had me dealing with decks of cards. Internally I represented suits as integers, with the following list to assist with the as_string method:

my @suits = qw(hearts spades clubs diamonds);

When I got to adding the initialiser for the class, naturally I wanted to be able to specify a string. The usual thing I'd do here is create a hash from @suits with the values as the integer array indexes. This time I came up with this one-liner to determine the index of a value in an array:

my $index = do { my $found; grep { $found = 1 if $_ eq $needle; $found ? 0 : 1 } @haystack };

It plays on the fact the grep in scalar context returns the number of matches; that is, the number of times the code block evaluates true. All this does is arranges it such that the block is true for every array index before the wanted value but false for every index after (and including) the wanted index. If $index == @haystack, then it wasn't found.

Its certainly not optimal - a binary search is always going to be quicker, and you'd nearly always want to use the hash method if you were doing it many times, but it was certainly fun to write a cute oneliner to do it.