Sunday, 19 February 2012

Tools for sloppy programmers

Most programming languages have to keep things neat and tidy, but in the past week I've realised at a couple of points that I don't want to place too much responsibility for tidiness on my users - and that sometimes untidiness is likely to be positively welcome.

The first of these was was the outcome of a struggle to deal with circular references in dependency chains. Until today, I'd been trying to track these down at the time the circularity was created - every time a new reference is added, I search the dependency tree from that point, to see if there are any cycles. The problem with this was how to resolve the cycle. Initially, my approach was to save the user from themselves, deleting the final link that causes the cycle. However, this wasn't as sensible as it first seemed. I didn't want to delete the new link that had just been created - the cause of the problem was more likely to be an old link that was no longer so interesting to the user. But as it turned out, it was much harder than I thought to guess which dependency is uninteresting, or even "old". As more interactivity has been appearing in the language, dependencies accumulate pretty quickly, and many of them would be bad ones to disconnect (for example, between an a value interactor and the value that it manipulates).

The resolution to this was a realisation that circular dependencies are my problem, not the user's. I've decided to allow cycles in the graph, and I simply have to remember not to follow them when making updates. In fact, this is a lot easier than deciding how to fix them.

The second sloppy feature was discovered partly through boredom, as I was implementing and testing map functions. I was often creating multiple values to map over, and it was necessary to assign or adjust each one before carrying out the map. To save myself time, I decided to initialise each new value to a random number, rather than assume that the user will assign it or derive it from something sensible. As it turns out, this has been a lot of fun - I keep discovering interesting new colours that I wouldn't have thought of creating. Another case of a behaviour that wouldn't really be considered in a "serious" programming language, but for sloppy programmers, getting variables with random initial values seems kind of cool.

No comments:

Post a Comment