Archive for the "Rants" Category

Code Style

One of the biggest annoyances I have with dealing with other people’s code is when they don’t use a sensible style. Obviously there have been many arguments over time about certain aspects of code style (brace placement, indentation, etc.) – but this isn’t really a problem as far as I’m concerned. I couldn’t care less where a given project has the braces placed, or if spaces are used for indentation, as long as it’s clear and consistent. This is something that recently irked me when I came to do some changes on Choob for the first time in what’s probably years.

From what I can tell (I wasn’t on the original team – so only have the code and documentation to go from) there was never a set of style guidelines drawn up when the project started. This, along with people like myself submitting code later through the project, has lead to a mix of code styles being used – and as a result the code is a bit of a mess in places. I’m pretty sure I’m to blame for some of this, so I’d love to fix it, but that’s a bigger problem than it first seems for a couple of reasons; the sheer number of lines of code it would touch, and getting everyone to use the new format going forward.

The first of these problems is less about the logistics of making the change than the problems posed afterwards. If I change the format of every class in the project, I’m going to have my name against pretty much every line of code when viewed in the source control system. Sure, my change was only superficial, but this doesn’t matter when it comes to running “svn blame” to work out who broke what. This is a tricky one, and one I’m not sure there’s a good solution to, other than to make sure that the commit with the format changes in only has those, such that people can then look at the previous revision, which hopefully has the name of the person responsible in it.

Looking at the second problem there’s a whole other set of challenges faced. Choob doesn’t have too many active developers, which I’m not sure would make it easier or more difficult. The numbers being small certainly makes it easier to get the word out, but because of the infrequency with which work is done – it’s entirely possible that they’ll forget that there is now a proper style and eventually the code base ends up back where it started. This can be made easier through IDEs with formatting features, and the ability to distribute a set of rules (I certainly plan to do this with Eclipse if I do reformat the code), but there’s no doubt at least one developer who doesn’t use an IDE, or uses one that hasn’t had the settings created for.

These are both great reasons why you not only should, but need to set out some code style rules at the start of the project. At work we’ve got projects that have strict rules as to how code should be laid out (with the Java ones having approved formatter settings ship with the internal build of Eclipse), and as a result the code base is consistent. Admittedly there are also measures in place, such as code reviews, that wouldn’t be practical in the case of something like Choob (where all the developers are working on it in their spare time around work/university), but having had an agreed style from the start is a huge bonus.

So, what makes a good code style? Well most languages have a set of conventions or even a set of “standards” specified by the creators of the language (for example Sun’s for Java), so in my opinion it makes sense to use these. This way it’s consistent with what developers are likely to find in other code bases (at least, I hope so) and therefore reduces the barrier to entry. There is obviously the problem of ending up with a lot of idiomatic code, but as long as it’s a widely known way of doing things – you should be able to get away with it (Perl’s returning undef for failure for example).

Unfortunately even with this there’s bound to be some argument that comes down to the braces – and I have to admit to there being one element about coding that frequently irritates me with them. Unlike the majority of arguments, however, it’s not about where to put them – but the lack of them when the language makes the optional. Sure for a one line if statement the additional braces can seem like a lot of wasted code, but what happens when a year or two down the line someone comes along and needs to add something? If they’re not careful they can very easily fall into the trap of not adding in the now required braces, and all of a sudden some of the block isn’t conditional. Equally the other side of the argument exists, where a conditional statement is followed by another that is expected to be run regardless, but is indented to the same level – making it impossible to spot at a cursory glance. Having seen both of these it’s never pretty, and for all its sins Perl manages this well be mandating braces in these very situations (obviously Python’s use of whitespace also avoids this problem).

Of course, part of that problem stems from indentation, and I’d hope that requiring sensible indentation goes without saying when discussing good code style. This, when combined with clear code and written in a consistent manner should make it easily maintainable – which is very important in any project that’s actually going to last.

With all of this in mind, I’m currently trying to find a sensible set of format guidelines that work well on the Choob project and can be automated within Eclipse, which I’m hoping I’ll be able to get into the code base and improve the experience for everyone. This is likely to be a bit of effort, and involve looking for the most common code style at the moment, but hopefully I’ll get something sorted this month (and then get nothing but complaints for the months afterwards!)

 

English Football

So, this week saw the end of the first transfer window in the English football season, and therefore lots of high profile movings for large amounts of money (especially with Manchester City getting a cash injection from their new owners). This got me thinking about the state of English league football, and I don’t like it.

It’s been going on for a while really, with the domination of Manchester United and Arsenal of the Premiership (between them winning all but one of the first 12 seasons of the league’s existence) and the presence of Chelsea and Liverpool within the group that have become known as “the big four” – a name not given to them for the average weight of their players, but their bank balance.

With the exception of Blackburn Rovers (who were the one exception to Manchester United/Arsenal’s rule of the first dozen seasons) the only team to have won the premiership is Chelsea, who first lifted the trophy at the end of the 2004-05 season and retained it the following year. Of course, it comes as no surprise that they managed this after a large cash injection from their newfound Russian owner, Roman Abramovic. Many accused them of buying the title, which is a fair comment, but also a fair tactic.

These days it seems that the league is more and more about how money you can invest in buying players at the inflated premiums they seem to have at the moment. Manchester City, as mentioned above, have recently acquired a large cash injection and used this to break the English transfer record with their shock purchase of Robhino. Reports are also around that they’re willing to offer local rivals Manchester United up to £133million for Christiano Ronaldo when the January window opens. This is just ludicrous, but the owners want to get some silverware, and this is the way they’ve chosen to go about it.

All of this, to me, makes the league far less entertaining. You can predict, with almost certainty, that one of the big four will win the league, and it probably won’t be Liverpool. You can guess that the smaller teams, probably those recently promoted such as Hull and Stoke, will get relegated – and you know that the rest will fall somewhere in the mediocraty between. It’s not that fun.

Contrast this, however, to different leagues in other sports such as American football’s NFL. In this league there are salary caps, stricter rules on transfers between teams (with free agents and restricted free agents etc), sharing of revenue from television and ticket sales between teams regardless of size and, by no means least, the draft. In this each year the worst team from the previous season gets to select the player they most want from those coming into the league from college football, giving them the opportunity to get the best new player before the other clubs (who pick in order of success with the Superbowl winners going last). All in all this leads to a league where, as the phrase goes, on any given sunday any team can beat another – regardless of form, as was shown with the Superbowl upset this year where the Giants beating the Patriots (who had been unbeaten and had beaten the Giants at the end of the regular season).

Of course, there’s no way FIFA could introduce something similar into football now, the leagues are far too established and there’d be uproar from fans of the currently successful clubs. It’s also worth remembering that the premiership has penalties for finishing low down (relegation), where the NFL has anything but. With this in mind I guess we’re going to be stuck watching the big four continue their dominance, and perhaps we’ll see Man City make something of the millions of pounds of investment, but for entertainment – I’ll be glad happily watching the NFL now that the season has started again.

 

Dilbert.com

Congratulations to the guys responsible for the redesign of Dilbert.com, not only does it now take forever to load with the mass of flash and other nonsense that has been dumped on it, but the comic doesn’t display (using either Firefox or Opera on Linux with the latest flashplayer). It somewhat defeats the point of a comic site and this whole thing looks like the idea of some sort of PHB, so I wonder if the irony will be apparent to them.

 

Buses

Buses are the worst form of public transport in existence. This is a fact that I had grown to accept and understand during my time living in Leeds, I knew that they weren’t going to show up on time (if they showed up at all) and I accepted it. Unfortunately I’ve since moved to London where the public transport system (tube and DLR anyway) works more often than not.

So, when I come to head back to Leeds this weekend, I have no problem navigating from my flat to King’s Cross, nor from there over the hundreds of miles back to Leeds; even going so far as to arrive early! Happy with the progress public transport had allowed me to make thus far I wandered out of the train station and to the bus stop. This is where the problems arose.

At the bus stop is a sign with the next three buses, none of which were the one I wanted. I consulted the timetable, and it said “at least every 10 minutes” so I figured that’d be fine. So ten minutes pass. Then twenty. Eventually the sign now displays three of the bus I want, with the ETA of “due”… great. Finally, after about thirty minutes they all show up at once.

Ah well, I did eventually make it here, but I bet it’ll only be worse on Thursday when I come to make the return journey.