Archive for May, 2007

Goats, Cars and Perl

Wednesday, May 30th, 2007

A couple of years ago, I read “The Curious Incident of the Dog in the Night-Time” by Mark Haddon. The book mentions the Monty Hall problem. I won’t waste bandwidth repeating the explanation of the problem here as the Wikipedia article is very good.

I tried to explain the problem and why it is confusing to a friend. She point blank refused to accept that there could be a strategy or that one door had a higher probability of being in front of a car (or kidney) than another.

To settle the matter, I wrote an implementation of the game in perl.

goats-and-cars.zip

If your computer doesn’t have perl installed, you will need to install an interpreter. ActivePerl works for me.

If you don’t understand the probability; first, play a few games yourself without cheating. Then, play in “cheat mode”. Then, play with more doors (say 10). Then, play in cheat mode with 10 doors.

If you’re still not convinced, get the computer to play 10 000 or so games against itself with the different numbers of doors and different strategies. Changing should be the best strategy.

Looking back at the code after a two year gap, I feel a bit nostalgic for perl. I stick mainly to PHP and JavaScript for work these days. While I don’t miss some of the eccentricities of perl (OOP always seemed like a hack and the lack of arguments for functions is just odd); I do think that as a language for hacking something together in an afternoon to show to your friends, it’s hard to beat.

Does programming turn you into a grammar Nazi?

Sunday, May 27th, 2007

Recently, I had an exchange on 43things.com about the use of the passive voice.

Something that I love about the internet is that it allows you to find people who are up for a discussion of the most arcane things. I can never talk about grammar with my friends or family, which is perhaps quite healthy and for the best.

What’s more, because of the setting, you have a chance to check your facts and develop your responses in a way that is impossible in real life. Thank you Google and Wikipedia.

One of the points of this discussion was that the passive voice can obfuscate the meaning and is less simple than the active voice and should, therefore, be avoided. I disagree with both reasons. A sentence in the passive shouldn’t be much of a challenge for any native speaker of English.

But I thought about this and wondered about the effect that spending so many hours a week programming has on the linguistic centres of a brain.

Consider a fragment of code like this:

my_div.appendChild(document.createTextNode(my_var.get_foo()));

A translation of this into English might be:

Take the value returned by the get_foo method of the my_var object and, using the createTextNode method of the document object, generate a TextNode object for that value. Append this object to my_div object using the appendChild method.

Any programmer might deal with hundreds of lines similar to this on any given day. Trust me (if you’re not a JavaScript programmer), this is simple stuff.

I dislike the fussiness and delusions of superiority that go with correcting other people’s language. I saw a group on facebook recently for people who always carry red pens so that they can correct menus which contain grammatical and spelling mistakes. Not only is this rude (and possibly xenophobic in some of the situations listed by the group), it also misunderstands the point of language and its evolution. Communication is the aim of speech and writing. I’m very much opposed to the idea of Linguistic prescription. To quote dear old Winston Churchill, it’s “the sort of bloody nonsense up with which I will not put.”

However, programming languages (for very good reasons) do have strict rules of syntax.

Consider:

my_div.appendChild(document.createTextNode(my_var.get_foo());

Hopefully, any programmers reading this will have spotted the mistake more or less instantly.

Just by force of habit, programmers tend to end up being fairly precise when it comes to language. Or perhaps, it’s that people who are precise about language end up working as programmers. I just hope that bashing my mind against compilers for years won’t give me any silly ideas about how human languages work.

I also have to admit that writing about grammar scares me. I hope that I haven’t made any speling mistakes and that the passive voice hasn’t been used too much.

Purpose for a Singularity

Saturday, May 26th, 2007

Here’s a short story that I wrote a few weeks ago.

Purpose for a Singularity

Standing up for slow computers

Saturday, May 26th, 2007

I work with computers a lot.

I write PHP, SQL and JavaScript for a living and have a rough idea of what a usable web site looks like. You might have guessed from my choice of theme for my blog that I’m not really into frills. At work, I leave all that in the more than capable hands of our resident CSS and PhotoShop guru, Saul Howard.

However, designing web sites is all about the user’s experience and I am very interested in that.

As anyone who has designed a web page will be able to tell you, consistency across browsers is still some way off. To avoid the pitfalls of this, we keep a variety of computers in the office. In fact, I’m using an ancient PIII 700 box right now with a 14’’ CRT monitor. I never let a web site out on the web without first checking that it is usable (if a little cramped) on this machine. My life would be somewhat easier if I could put messages like this:

on my pages but it just wouldn’t feel right.

One of the buzz words in web design for the last couple of years has been AJAX. When implemented well, I think that it does add greatly to the snappiness of web pages.

However, turning web pages into full blown applications does have a downside. A lot of AJAX pages seem to ask much too much of a user’s browser and sometimes (even with the faster machines in the office) my CPU will run at 100% just to surf the net. Reading web pages on an old computer is often an exercise in pain unless you stick to Wikipedia (and my sites:)). A technique for improving the performance of web pages can fail completely.

I watched this video the other day. For what it’s worth, I think that the video has overly dramatic music but it raises some interesting points. It finishes up by predicting that $1000 computers will one day be more powerful than all the human brains on the planet. I doubt that the arithmetic for this is particularly meaningful. Even if we do have supercomputers for pennies; I fear dreadfully that all this extra power won’t cure cancer, forecast hurricanes or even enslave us as deluded brains in jars. Most likely the extra power will be eaten up by increasingly untuned pages in fantastically bloated browsers.