I write a lot of open source code.
This is not, however, the same as saying I write a lot of useful open source code. I suspect 90% of open source code I’ve written has never been productively used by anyone except me (and probably half of that 90% hasn’t been used productively by me either and was just an amusing hack). That’s ok though. It’s not really meant to be – when I create a project I actively intend for other people to use I put a bit more effort into it, but for the most part it’s really a case of “I wrote this. I don’t care about it that much. Maybe someone else will find it useful”. Most of the time they don’t, but far be it from me to judge what would and wouldn’t be useful to other people among my random hackings.
There was a nice example of this the other day, when I had the following exchange on twitter with Josh Reich (transcribed in IRC format because I don’t have a better twitter transcript convention):
<@i2p> I'm stealing some java code found on the internets written by one @DRMacIver - thanks! <@DRMacIver> @i2pi You're welcome. :-) Which code? <@i2pi> @DRMacIver FlatteningIterator + its recursive cousin <@DRMacIver> @i2pi Oh,wow. Code from the dawn of time. :-) <@i2pi> @DRMacIver It's funny - years ago I used your FlatteningIterator, but never realized it was yours until I went to grab the code again today. <@DRMacIver> @i2pi Glad it was useful! I'm never sure how much, if any, of the random code I put out there is.
That’s all. Nothing earth shattering – but it was nice to get a thank you for a little bit of code I wrote once upon a time, and to know that that code had helped someone out. It made me smile on what was otherwise turning out to be a fairly meh day, so was extra appreciated for that.
The code in question is here. It’s nothing special – it’s an iterator that recursively descends into other iterators in a depth first traversal. It’s one of those things that just about anyone could write, but if someone else has already written it you’d probably want to reuse their version rather than write your own owing to the presence of a few fiddly edge cases.
To be honest I’d forgotten all about it. I actually wrote this code about 8 or so months after I first really learned to program. It’s not bad code given that: I can’t see anything obvious about it that makes me go “Oh my god, I did that?”, though the design of the overall API is a bit icky (you have iterators which return a mix of values, other iterators and collections, and it descends into every iterator or collection it finds and returns every value), but given the specified behaviour the code is ok. Except for the bug I just noticed where the code for supporting arrays is completely wrong. The commenting style is a bit too “I should write comments as much as possible” so a little over-obvious. Still, it was nice to know I wasn’t a complete idiot back then (the Array bug is an instance of stuff I seem to still be guilty of today – not testing enough – so I’m not counting that)
Anyway, I enjoyed being reminded of this code, enjoyed the fact that it was useful to someone and appreciated being thanked for it. I didn’t really have anything more profound to say than that.