Tag Archives: open source

Open source nostalgia

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.

This entry was posted in programming and tagged on by .

Code for you to play with

As you might have noticed, I have a slightly silly number of google code projects. Most of these are crap or abandoned, although (I think!) there are a few good ones there. Rather than spamming the world with endless open source projects each with their own separate sites, I’m moving to using freehg.org for such things. You can find my code at http://freehg.org/u/DRMacIver/.

Right now what’s there is an alternative collections API for Scala that I’m tinkering with (it’s currently very basic, and the implementations that are there are more to explore the API than intended for serious use) and some random little Haskell projects I’ve written.

In the best spirit of open source, almost everything there is undocumented, uncommented and lacking a working build script. You can consider anything there that doesn’t come with an explicit license to be released under the WTFPL.

This entry was posted in programming and tagged , on by .

Open source project breakdown.

I realised today that I actually have a fairly large number of open source projects published online (all on google code. Another thing I realised is that I should fix that).

I also realised that some of these are totally defunct.

I thought this would be a good time to do a quick breakdown of them, explaining what’s there, what they do and what their current status is.

JTypebuilder

Code generator for creating immutable data structures in Java. The idea was to define simple datatypes with a record notation and get an immutable class from them with correct equality, hash code and toString implementations, getters for the properties and a builder class for generating instances.

Status: Very very dead. It was at best a weak idea, and I have no interest in pursuing it. Use Scala’s case classes instead.

Generators4j

A brief foray into functional programming in Java. Lazy generators with functions like map, filter, etc.

Status: So dead. I didn’t get very far before concluding that trying to do this in Java was unusably awful.

Lazy Strings

Experiments in efficient representation of String types, with the aim being to provide a drop in replacement for java.lang.String with a different set of performance characteristics. Started in Java, moved to Scala.

Status: Just resting its eyes. I’m not doing much with this at the moment, but I occasionally peek at it and will probably factor out some of the ideas and turn it into a more tightly focused library.

Ranged Types

Very small Scala library for statically checked numeric ranges.

Status: Awaiting a use case. I occasionally think about picking it up again, but then I wonder why. It’s a fun idea, but I don’t actually have anything I need to use it for and as far as I can tell neither does anyone else.

SBinary

A small library for binary serialization and deserialization of Scala data types, based on Haskell’s Data.Binary.

Status: Very much alive. I’ve just released version 0.1 RC1, am using it as a dependency in other things and am continuing to tinker with it to improve its usability.

Prefer Scala

A wrapper around the Java preferences API designed to be nicer to use from within Scala and support a wider variety of preferences in a typesafe way. Uses SBinary to serialize Scala types to and from the preference backing store. It’s been factored out of the code for Hector’s Reminder Service.

Status: Fledgling. I’ve only just released it. It’s very small, and I intend it to remain so, so I expect to push it towards a 1.0 fairly quickly and then have it enter maintenance mode where future updates are just to fix bugs and bring it into line with the latest versions of its dependencies.

Hector’s Reminder Service

Unlike the other ones, this one is an application. It’s a small cross platform status bar application based on QT which gives you reminder messages on a semi-regular basis. Designed to be unobtrusive and simple and intended for the occasional casual reminder rather than of specific events. Uses “Prefer Scala” for persisting of state between application runs.

Status: Again, quite recent. I have a semi-official version released which works and more or less does what I want. I’m intending to polish that, add a very small number of new features (currently planned are a more expressive way of specifying message intervals, the ability to temporarily suppress a message group and possibly a simple API for other programs to interact with him) and then declare it to be feature complete. Once it’s reached that point it will enter a similar state of “Updates are only to fix bugs and match new dependency versions”.

Baby’s first open source project

I’ve decided to start a new personal project, and I’m going to make it open source from day one. The project is called JTypeBuilder and is hosted at Google Code and released under an apache 2.0 license.

The basic idea is that it is used for generating data models and producing an awful lot of associated boiler plate code. It produces immutable classes for representing the data, mutable classes for generating the immutable ones and methods for passing back and forth between them. The immutable classes all have the obvious equals and hash code implementations, as well as a toString method which produces a JSON like representation of the class.

It currently just consists of a couple freemarker templates and some simple wrapper code for them. When I get around to it I’ll add a parser and command line interface for nice representation of the data models.

I have vague intentions of using this for some sort of simple ORM package. Another possibility is using it as part of a compiler backend for targeting the JVM – it can be used to generate the data types. All of this is in the future though – right now it’s simply a tool for reducing boiler plate code (and a fairly incomplete one at that).

Update: Phew. That was a succesful day. The parser and code generator now work, and are hooked together with an extremely rudimentary command line interface (it’s little more than a proof of concept). Still to do are improvements to the interface and customisability, as well as general improvements to code generation and parsing. Nonetheless, there is now a working tool there. Yay.

Actually, come to think of it, the biggest thing that needs fixing at the moment is the build.xml. It’s a really shocking piece of spaghetti XML put together with the intent of having something working quickly rather than actually producing a portable build script… Lots of hard coded paths.