Tuesday, 31 January 2012

Ubuntu Linux desktop 11.10 proxy settings solved

Watch out for system proxy settings in Ubuntu Desktop 11.10 (at least in its LXDE guise, which is what I am running in a VM). The control panel "Network" has disappeared and even if you install it using apt or Synaptic you'll find that it doesn't have any proxy options. gconf does, but seems to have no effect. Answer is to edit /usr/share/applications/chromium-browser.desktop and append

--proxy-pac-url="http://example.com/"

to the Exec line.

Saturday, 24 September 2011

Fun with Robots, Arduino and Android

Together with Mike Hogg from my firm, Zühlke Engineering, I recently developed a demonstration project over a three-day training exercise. We purchased a simple robot and added a set of three infra-red sensors capable of detecting a black line marked out on the ground with electrician's tape. We had to develop a line-sensing algorithm and control logic to follow the line and stop at stations (a short length of tape at right angles to the line) until instructed to move on.

We followed a test-driven development (TDD) approach for C++ using CppUTest, as described by James Grenning, to create a state machine to turn sensor readings into motor control instructions (with hindsight, we might have saved time by resorting to the Machine Objects library). To my surprise, once we loaded the finished firmware to the Arduino board, it worked very well with only a bit of tweaking of the motor speed settings corresponding to "hard left", "slight left" etc.

Then we linked this with an application we developed for an Android tablet computer (Motorola Xoom) that could be used to instruct the robot to go to any selected station, pick up/drop a "payload" (only conceptually) and return to base. The two components communicated by Bluetooth radio link.

Finally, the tablet app was linked via a RESTful Web Service interface to an "enterprise" system developed by other colleagues on the training course, that controlled the whole delivery network and knew which consignments had to be delivered to what stations. The tablet would send a message to the enterprise server telling it where the robot had arrived, and receive back an instruction containing the name of the next station to move to. The robot would then move off automatically after 5 seconds.


The whole thing was enormous fun (as well as very instructive) and was demonstrated successfully to the entire group (see photo).

Jason Gorman and Simon Peyton Jones, among others, have recently been at pains to point out the shortcomings of IT education in the UK. Thinking about the above exercise, it occurred to me that it is just the sort of project that could engender enthusiasm for the subject from a wide range of school students. It involves lots of varied tasks from assembling the hardware to designing the user interface, and of course the devising of suitable protocols between all the components.

Simon Peyton Jones of Microsoft Research will be presenting an interactive talk about Computing At School on 2nd November in London, and the following month (6 December) Mike and I plan to do a session on the Robot Shop exercise at the same location. Anyone interested will be most welcome.

Wednesday, 10 August 2011

Generate test data for Java development easily

A colleague has just pointed out the release of Andy Gibson's DataFactory library as a Maven artifact. It generates arbitrarily long lists of random names and addresses, dates, date ranges (with arbitrary constraints), random selections from lists, numbers, strings, Internet addresses etc. etc.

Sunday, 19 June 2011

Inspiring the next generation of developers

Jason Gorman has published a thought-provoking opinion piece asking why schools are doing so little to promote IT as an enticing career option and to equip kids to take advantage of it. His analysis points to a lack of suitably qualified teachers (so what's new?) and a commensurate lack of ambition on the part of exam boards to make the syllabus industry-relevant.

Do get in touch with Jason to take part in a summit at Bletchley Park (where else?) on 25th August 2011 to identify practical measures that can be taken to improve this dire situation.

I think this is an issue the BCS should be addressing with all dispatch instead of tying itself in knots over some elusive ideal of making all IT practitioners professionally qualified. Some of the most proficient software practitioners I know have no professional qualifications at all.

Wednesday, 25 May 2011

Perils of using an elderly FitLibrary

I learned about a really useful tool today while trying to hunt down a bug in a set of Fit automated acceptance tests.

Last September, my colleague Darren Bishop had set up the automated acceptance test infrastructure for a Maven/Java project I subsequently joined. He used version 20080812 of the Maven dependency (org.fitnesse.fitlibrary), probably because it was the latest available in the Maven Central repository. Thus the stage was set for my troubles last night and this morning!

While working on a small enhancement with a developer in the customer's product support unit, I noticed that one of the Fit tests was producing a blank report and not being counted in the summary totals. A comparison with other spreadsheets that did run properly revealed no significant differences.

Back at base, it quickly became apparent that I had to single-step through the program to find out where it was going wrong. But I could find no source jar for this version of fitlibrary - the latest dependency version available with source was from 2006. What to do?

After a futile attempt to desk-walkthrough the code of FolderRunner and SpreadsheetRunner, Keith Braithwaite suggested decompiling the class files. JD-Eclipse to the rescue! I installed it in my Eclipse and found it so insanely useful that I will never want to be without it again. Basically it creates beautifully formatted source code for you on demand (obviously without the programmer's original comments and documentation). This means that you can set breakpoints and single-step through library code even if you have no source attachment for your library. Installation was really easy. After that, if you single-step into a library method, the "source" is opened automatically. You can also open a .class file directly in the package explorer by browsing the libraries on your project's build path.

There's just one slight gotcha: the line numbers in the decompiled code rarely match the original, so if the class file contains line number annotations your instruction pointer and breakpoints may appear to be a few lines away from the location reported in the debugger's thread view. Ignore the cursor and read off the current line number from the comment at the start of each line. You can turn off the display of metadata and line numbers in the JD preferences, and I have done so - it needs a restart of Eclipse to take effect, but setting breakpoints is much easier afterwards.

So, what was the solution to the mystery?

In the FitLibrary class SpreadsheetRunner, the method collectTables() used an Iterator to return the rows of the test script one at a time and convert them into arrays of values that the runner could subsequently invoke to execute the test:

HSSFRow row = (HSSFRow)it.next();
HSSFCell[] cells = getCells(row);
String[] borderedCellValues = getBorderedCellValues(cells, workbook);

Unfortunately, getCells() dimensioned an array of HSSFCell objects using the value returned by a row:

private HSSFCell[] getCells(HSSFRow row) {
int maxCell = row.getLastCellNum();
HSSFCell[] cells = new HSSFCell[maxCell];
...
return cells;
}

When the row was "empty", getLastCellNum() returned -1, which caused the next line to throw a NegativeArraySizeException. This exception was caught by FolderRunner.runFile(), which attempted to report the problem to the standard output, but this didn't appear in the Maven test log.

I have not found out what makes POI decide that a row is "empty". There was only a single spreadsheet row in the entire suite of tests that was interpreted in this way. I achieved a workaround by pasting a copy of another blank row of cells onto this row, but the danger is that anyone could inadvertently reintroduce the error.

Lessons:


  • You can still use the Java debugger if you don't have the source. JD-Eclipse worked very well for me, even though it is only at version 0.1.3. (I wonder if it will decompile classes written in other languages such as JRuby?)

  • It's time someone made a proper Maven dependency, with sources and javadoc, of the latest Fit, Fitnesse and FitLibrary versions - the current version of FitLibrary, dated April 5th, 2011 in fact solves the exact problem I encountered!



Friday, 11 February 2011

So long then, Ken Olsen

Ken Olsen, founder of DEC, passed away aged 84 on Sunday 7th February. Read a short obituary here. I used to consider DEC as the nimble young upstart snapping at IBM's heels and making computing affordable. My first real computing experience was on the undergraduate DEC-10 system (running TOPS10) at Leeds - and it shaped my subsequent career, though various PDP-8 and PDP-11 minis featured even before that. RIP Ken.

Saturday, 29 January 2011

The oddness of socks


In a moment of boredom, and prompted by a recent survey of wacky interview questions, I plotted out the probability graph of finding a matching pair of socks at random, based on the number of black ones among 25 grey ones. It turns out that you need only 3 black socks to drop the probability of a matching pair from 100% to 80%; 9 in 25 gets you to 60%. Anything over that makes very little difference up to 25, where the probability drops to a minimum as you would expect. After that it starts rising again slowly, but never reaches 100%. YOU NEVER HAVE A LESS THAN 48.9795918% CHANCE OF GETTING A MATCHING PAIR. I find that oddly comforting.