Sunday, December 9, 2012

Programming a Programming Language - Gherkin

I've found myself essentially writing a programming language. It's nothing fantastic and I'm sure there are probably much better ways of doing this but having worked through a couple of structures now I find myself surprised by just how simple it is really.

Why am I doing this? For the Manaiakalani project I wrote a program which, lacking creativity, I called "InitialLogin". Basically, when a computer has just been imaged, the computer has to be set up by the user. Given that I only ever wanted to maintain one image for ALL of the schools, I wanted certain things to happen when a user selected which school they belong to.

Things like set up network settings (wireless mainly), install any programs that the specific school wanted etc.

And then there's the whole flexibility/usability problem. If I wanted to add another school, I should just be able to throw together a bit of a definition file, spend a little time on branding (you'd be surprised at how much value people see in a simple image change) and have a completely customized set up for them within a week.

And it's all worked fairly well (There's still one bug that I haven't been able to fully solve) except... I realised that it needs more. Take a high school setting. Things are a little bit different. As well as school wide settings, there are also applications that could be installed for particular subjects. Sort of like a computer version text books. You'd only issue text books to the students taking those particular subjects. There are applications that can come in handy for electronics or music or example.

So we're now into flow control. For those now in the know, a lot of programming is basically being able to control the flow by using constructs like "if... then... else...". It's actually a really natural construct. I giggled when I heard someone leaving a message on an answering machine:

"Hi, it's Bevan. Unfortunately I've missed you. If you're able then give me a call otherwise we'll talk some other time".

Okay - so the language isn't exactly the same but an else is just so much shorter to type.

And loops (something I'm not accounting for though I can imagine what it'd look like) - being able to tell a computer to rinse, repeat. Much easier once you've figured out how to evaluate conditions.

What does this mean? The piece of the project that I'm most proud of in terms of technical coolness is only going to become cooler. The extra flow control is only one of the changes. I'm also looking to have it do a quick survey of the wireless points around and make an informed guess of the school that it's currently in to take away one more question (or to limit those choices). Given that I'm looking to have a rescue partition on every device, then the answers to various questions could probably be stored on that rescue partition so the next time a user decides to reimage their machine, the initialLogin program could then seek out that file, confirm that the user wants to use those settings and go on it's merry way - a 2 second setup single click setup rather than a 3 minute one on subsequent reimages (with the option to change those settings of course - for those who move schools for example).

Anyway, this all means that I'm that much closer to releasing my first application as an opensource project - one that encourages more collaboration rather than the more backdoor - download the source from a repository and use it for yourself. The gherkin in my tartare source.

Of course, this also means I'm going to have to make be all sorts of justifications.

For example, I find procedural programming simpler and more stable in certain situations rather than object orientated programming.

I want to be able to plug in different interfaces depending on need - i.e. qt, ncurses, gtk - the only one of which I'll be working on, unless I have a personal need, is gtk. This leaves a question around which version (2 or 3?). Currently I'm finding 3 frustrating as the documentation just isn't up to the code. For example, I love using indents to better arrange information. The object I was using in gtk2, alignmentbox, to achieve this is just really poorly documented (previously you needed 2 arguments to initialize. Now it only takes one... but which one?). I guess I could change the way that I display things or better yet, go through the code and try and document it myself, but for the time being, I'm quite happy to write gtk2 code as closely to gtk3 code as possible (to make the transition easier in the future).

Part of open sourcing something is letting it go... Whether that means the code is opened up for modification by a community with community decisions, or whether forks are strongly encouraged to enable it to be built for differing situations (with a view to try and merge as many of those forks where it makes sense) is something still to be figured out. Personally, I favour the second one as I think it leads to a greater range of diversity and hopefully a clearer landscape in terms of purpose.

This could be compared to the relationship between Debian and Ubuntu. While Ubuntu is derived from Debian, the development that goes into Ubuntu feeds back into Debian - in a much more community and stability focused way. So 2 distributions with very different purposes essentially evolving with each other.

What do others think? This of course assumes that I can grow a community interested in this sort of deployment/these sorts of tools.

No comments:

Post a Comment