Monday 26 October 2009

I love Python

Today's distraction is Python and scripting languages, so non-programmers should probably go browse YouTube while the nerds get their freak on.

Back in the day when I had a job, I found myself assigned to a long-running major project that relied on lots of special scripts to help the build, validation and release processes. The problem was that the project was so long-lived that the people who had written those scripts had left ages ago and had taken their specialist script-writing skills with them. Since everyone else was so busy writing the project code, they had no time to spend on the scripts and besides, they were C++ wonks and treated the build scripts as magical voodoo that either worked, or didn't. Increasingly, they didn't.

As the project had grown, it had changed. Source code wasn't where it used to be. New types of resources were added in new subdirectories and the scripts weren't updated to process them. Additionally, poor design required stupid bodges like the source tree being subst-ed to a specific virtual drive on everybody's PC, or the script simply wouldn't work.

Shortly after I joined the project, I was asked to run the validation software over our source code, so we could send a report to the customer showing them how full of quality it was, which it was, it was just the non-deliverable scripts that we'd let ourselves down on. Anyway, I dug out the validation script, ran it and was rewarded with abject failure- the script couldn't find PC-Lint.

Digging through the script revealed a number of horrors. PC-Lint was installed on a single machine for licensing reasons (presumably) and was called remotely by the script. Problem was, the company naming scheme for PCs had changed since the script was written, so the script could no longer find the computer with PC-Lint on it. I fixed the broken link and realised that the machine with PC-Lint wasn't even a server, but was some engineer's desktop PC. Better still, the engineer had switched projects and as required by our security standards had wiped his PC and installed a clean image onto it, without PC-Lint. Where's the installation media for PC-Lint? Best ask our tech support people, they'll raise it as an issue on their magical issues database and ignore it.

The other major horror I found was the script itself; it was written in Perl. Perl is a wonderfully powerful language and I'd always wanted to learn it, so here was the perfect excuse... er, opportunity.

The problem was that I was trying to learn Perl by trying to fix a complex existing script rather than by writing my own stuff from scratch. Perl's philosophy is "there's more than one way to do it", which means that it makes very little demands on how the programmer writes his program. You can write very cleanly and elegantly, or you can write an incomprensible mess (like this post, but with more $, % and &). The code in question was very much of the second variety. Very clever code, but practically incomprehensible to any poor sod other than the original author. Great for job security, except that I collared the original author to have a look over it and he couldn't understand it either- too much time had passed between writing the code and re-reading it, he'd forgotten his original chain of thought.

I got it working eventually (after a certain amount of complaining from management that the other guy used to only take an afternoon and why was it taking me so long?) and delivered the report that proved how ace our proper code was, but after that, I started getting assigned all the script-fixing tasks by my team leader who unlike upper management knew exactly why it had taken me so long and why no-one else had run the script in over six months despite it being a weekly deliverable. Time and again, my mental gears clashed because all of a sudden the original programmer had suddenly used an unless statement instead of an if, which is even better in a one liner, because then the conditional unless is after the conditionally-executed statement...

Anyway, I began to wonder if there wasn't perhaps a better way to do things. A cleaner way. A way where an engineer could write a script, then six months later a completely different engineer could look at it and actually not have to spend the day flicking back and forth between the editor window and the language documentation, looking up obscure forms of use for common language features. Eventually, I looked into Python.

In contrast to Perl, Python's philosophy could be described as "There's one way to do it". Python code is generally a lot more readable than the average Perl script. Yes, you can write clean, readable Perl, but it requires discipline from the programmer that often isn't there. Generally, it's a lot quicker to get the gist of a Python program than for Perl, even for developers who don't have any background in either language (at least it was for the poor sods on my team that I tried my ideas out on). Sure, a lot of programmers will throw a fit at the idea that indentation matters, but if you threaten them with a really messy Perl script with plenty of regexp line-noise in there, they eventually give up and see things my way.

I rewrote a few of our Perl scripts in Python in my spare time and found that while a lot of text-processing tasks are easier to write in Perl, the Python equivalent is often more maintainable; six months later, I could still understand how the script worked. Perl makes for brilliant hacker-ish programs, Python can make for maintainable code, which is immensely important for a software engineering team, if you can convince people to get past installing yet another scripting language.

Tuesday 14 July 2009

Dogs and Peanut Butter

I have a pair of Cairn Terriers that specialize in doing nothing useful at all, so today I entertained myself over lunch by applying dollops of organic peanut butter to the roof of their mouths.

Watching small dogs try to de-clag their corrugated palates may sound like an odd way to pass the time, on account of it being an odd way to pass the time. Still, the dogs seemed to enjoy it and it beat the pants off of watching people fit double glazing to the house behind mine, which is how I spent a sickening slice of yesterday afternoon.

One of the problems I'm having with being unconstructively occupied is that I rapidly get sick of whatever it is I'm doing to keep myself busy. I got bored of reading about Java so I started reading about C# instead. I started a project using Imagemagick to help colour-correct digital photos; when I started it was originally going to be in Java, but then I got distracted by reading the C++ interface docs, so I switched over to C++, shortly followed by C# when those evil people at Microsoft let me download the Express edition of Visual C# 2008 for free.

This rapid shifting of goals and activities is because I have absolute freedom of choice and no-one to talk to and spin ideas off. Without other people around to talk to about project issues and whatnot, I find myself endlessly browsing the documentation (or worse still, Wikipedia) and getting distracted by interesting links or sidebars which point me in the direction of some new shiny technology that I suddenly feel the need to learn all about. Today, I was all about the VHDL and if I had the budget for it, I'd be out there buying an FPGA devkit right now.

I need a job. I need people to talk to and help set goals and boundaries. I need someone to make the tea.

Wednesday 24 June 2009

Wimbledon't

Tim Henman preparing to hit a serve. The left ...Image via Wikipedia

I hate Wimbledon fortnight. Both BBC1 and 2 are showing nothing but tennis all afternoon, which is quite rich given that they ought to be catering for non-sporty misanthropes like me as well as the upper-middle strawberry-affording class.

They've got good weather for it, at least. This is probably as a direct result of them spending a bajillion pounds on a sliding roof to keep the rain off the court. That's not to say they aren't getting any use out of their investment; yesterday they extended it to keep the scorching sun off of "important visitors" in the Royal Box. If it was our suspiciously ginger junior heirs to the throne, it's probably a good idea to keep them out of direct sunlight.

Enough of complaining about tennis; it's a very silly game and not even sexy female tennis stars running about in short skirts is compensation, especially not with all that grunting.Reblog this post [with Zemanta]

Wednesday 17 June 2009

Something for the weekend, sir?

I've got myself a job interview on quite short notice and it's finally forcing me to accept the uncomfortable truth; I need to get a haircut.

So what's the problem with that? Aside from getting unreasonably tense when strangers hold sharp implements to my neck (which is actually quite reasonable behaviour when you live in Salford), I haven't been to a barbers in quite some time.

At least twenty years, in fact.

No, I don't quite look like Cousin Itt from the Addams Family as I used to get my hair cut on a semi-regular basis by my mother. Sadly, my mother passed away earlier this year and this is the latest way I find myself missing her.

I'm living in dread at the prospect of finding out how much a short back and sides costs these days. I'll probably only be able to afford it if I get the job, but I won't get the job without a proper haircut.

Perhaps I should try the local college and let the trainee hairdressers have at it. This has the added advantage of putting me in close proximity to hot college babes. It has the disadvantage of putting me in close proximity to hot college babes who find 36-year-old men hitting on them to be deeply creepy and who can't cut hair.

Friday 12 June 2009

When Worlds Collide

In the good old days before physics and maths got all post-modern on us, the solar system ran like clockwork and the trains were always on time. Planets knew their place and wouldn't dream of spinning out of orbit and smacking each other in a Michael Bay-style extravaganza of explosions and mayhem. Unfortunately, standards have since slipped.

Actually, the idea that the planets were stuck in their tracks like some sort of cosmic Scalextric set was in trouble as far back as Newton, who could do the maths to prove the stability of a single planet orbiting the sun but wasn't able to produce a general solution to the problem of the Moon's orbit. Newton believed a general solution for all the planets was impossible and that the long-term stability of the solar system was thanks to God fiddling with the celestial clockwork every so often.

Thanks to computers, we can now run simulations of the solar system for billions of years into the future before tiny unknown forces like the mass lost by the sun due to the solar wind, or the effects of galactic tidal forces make a joke of the numbers. The possible planet-smashing predictions reported by the press are the result of 2500 simulations run by Jaques Laskar and Mickaƫl Gastineau of the Paris Observatory who in each run simulated the next five billion years of the solar system's future, up until the point where the Sun grows into a red giant and vaporises most of the inner solar system.

The interesting thing to me is what the difference was between each run: They changed the initial position of Mercury by a single metre.

In 20 of their cases, Mercury's orbit eventually went nuts; sometimes falling into the sun, sometimes smacking into Venus. Regardless of how Mercury flew off the rails, the peturbations it caused on other planets was enough to cause some serious orbital shennanigans, including a possible Mars-Earth smackdown of the Hollywood kind.

So, given time, the tiniest planet (Sorry, Clyde) can throw the solar system into disarray. Makes me think of the old joke about the Earth falling into the Sun if everyone in China jumped at the same time. Well, it might not happen right away...

One for Mythbusters, perhaps.

Oooh! I'm quite fat! what if I jump up and down for a really long time? What would happen first; the Earth falls into the Sun, the Sun eats the Earth or I get in shape?



Reblog this post [with Zemanta]

Thursday 11 June 2009

Stupid Eee keyboard...

I'm posting this using a Linux-based Eee PC 901 that I bought for my mother last year and ever since the last update to Firefox (3.0.4), the keyboard has switched over to US-English and won't switch back to UK layout. Fortunately, I've got a fix. From a terminal prompt:

sudo apt-get autoclean

Then switch the keyboard layout with the appropriate app in settings.

Red Faction: Guerrilla

I've been playing a bit of Red Faction: Guerrilla and while I think it's fun, there's some missed opportunities in there too.

The one that really bothers me is the AI of civilians. It's too good for what it is.

That's a bit of an odd statement, but to see what I mean, you have to go out of your way to watch the little folks go about their daily routine; people browse the (nearly empty) shelves of (nearly empty) shops, they lounge around, propping up the bar in pubs, they carry space two-by-fours around on their shoulders when you smash up their houses with deadly sledgehammer action. It all works towards a sense that they've things to do outside of being collateral damage for your high-explosive exploits.

The trouble is you have no reason to see any of it. Since you spend most of your time tearing around the wilderness in excitingly impractical space-taxis and Mars-buses, or running around military bases, you rarely see the effort the developers have put into the idle behavior of civilians. You've no need to explore the insides of buildings aside from picking up hidden Quantum Bomb caches that aren't really worth the effort. Most of the work put into civilian AI, especially indoors, seems to have been... not wasted, as that implies they shouldn't have bothered with it, but under-utilised, as the basic flow of the game almost never puts you in the thick of it.

That aside, I like the game. If only the sound guys could have got a bit further away from petrol engine sounds when doing the effects for some of the cars. I hope that if we ever do get to the point of terraforming alien worlds, we can do a little bit better than internal combustion to run our rides.

Anyways, 8/10, good effort.

In the beginning...

...was the word, and the word was "bored". Thanks to the economic downturn, I've got myself faaar too much free time on my hands right now, and there's only so much daytime TV you can watch before your brain melts and drips out your nose.

Note to potential employers: I'm not actually watching that much telly, honest. I'm practicing for SCJP certification, reading up on all those bits of C++ that Symbian programmers don't normally get to do (like templates and the STL) all at the same time as getting up to speed with C# and .Net. I've a stack of books two foot high on my coffee table and I'm really and truly reading them; I've even been sending the authors corrections and everything.

That aside, I'm getting bored a lot and I've not even got anyone to talk to about things and stuff, hence the blog. I can't promise there'll ever be anything to interest real people here, but with a bit of luck, it'll keep me sane and give me something sort-of productive to do.