Archive for programming

Other People’s Code

Posted in Education, mathematics with tags , , , on March 16, 2018 by telescoper

I don’t know if this is just me being useless, but one of the things I’ve always found difficult is debugging or rewriting computer programs written by other people. This is not a complaint about people who fail to document their code sufficiently to see what’s going on, it’s that even when the code is documented it seems much more difficult to spot errors in code written by other people than it is when you’ve written the program yourself.

I’ve been thinking a lot since I’ve been teaching Computational Physics here in Maynooth University. One of the standard elements of the assessment for this module is a task wherein the students are given a Python script intended to perform a given task (e.g. a numerical integral) but which contains a number of errors and asked to identify and correct the errors. This is actually a pretty tough challenge, though it is likely to be one that a graduate might have to meet if they get a job in any environment that involves programming.

Another context in which this arises is our twice-weekly computing laboratory sessions. Twice in the last couple of weeks I’ve been asked for a bit of help by students with code that wasn’t working, only to stare at the offending script for ages and fiddling with a number of things that made no difference, without seeing what turned out to be an obvious mistake. Last week it was an incorrect indent in Python (always a hazard if you’ve been brought up on Fortran). This week it was even simpler, a sign error in a line that was just supposed to calculate the mid-point of an interval. I should have been able to spot these very quickly, but I couldn’t.

What makes this so difficult? When given a mathematical calculation to mark I can usually spot errors reasonably easily (unless the working is illegible), but with code it’s different (at least for me). If I’d been given it on a piece of paper as part of a formula, I reckon I would have spotted that minus sign almost immediately.

One possibility is just that I’m getting old. While that may well be true, it doesn’t explain why I found debugging other people’s code difficult even when I was working on software at British Gas when I was 18. In that context I quite often gave up trying to edit and correct software, and instead just deleted it all and wrote my own version from scratch. That’s fine if the task is quite small, but not practicable for large suites written by teams of programmers.

I think one problem is that other people rarely approach a programming task exactly the same way as one would oneself. I have written programs myself to do the tasks given to students in the computing lab, and I’m always conscious of the method I’ve used. That may make it harder to follow what others have tried to do. Perhaps I’d be better off not prejudicing my mind doing the exercises myself?

Anyway, I’d be interested to know if anyone else has the same with other people’s code and if they have any tips that might improve my ability to deal with it. The comments box is at your disposal…

Software Use in Astronomy

Posted in Education, The Universe and Stuff with tags , , , , on July 21, 2015 by telescoper

I just saw an interesting paper which hit the arXiv last week and thought I would share it here. It’s called Software Use in Astronomy: An Informal Survey and the abstract is here:

softwareA couple of things are worth remarking upon. One concerns Python. Although I’m not surprised that Python is Top of the Pops amongst astronomers – like many Physics & Astronomy departments we actually teach it to undergraduates here at the University of Sussex – it is notable that its popularity is a relatively recent phenomenon and it’s quite impressive how rapidly it has caught on.

Another interesting thingis the continuing quite heavy use of Fortran. Most computer scientists would consider this to be an obsolete language, and is presumably mainly used because of inertia: some important and well established codes are written in it and presumably it’s too much effort to rewrite them from scratch in something more modern. I would have thought that Fortran would have been used primarily by older academics, i.e. old dogs who can’t learn new programming tricks. However, that doesn’t really seem to be the case based on the last sentence of the abstract.

Finally, it’s quite surprising that over 40% of astronomers claim to have had no training in software development. We do try to embed that particular skill in graduate programmes nowadays, but it seems that doesn’t always work!

Anyway, do read the paper yourself. It’s very interesting. Any further comments through the box below please, but please ensure they compile before submitting them…