Caius Theory

Now with even more cowbell…

OS X User has a virus

No not my computer, me. I've managed to pickup an acute coryza virus. It causes /dev/random to constantly pass data to /Volumes/nose. I don't think I got this from reading email, but I'm pretty sure it was a windows user who passed it to me.

If I flush my partitions to disk every now and then I can get by with a clean /Volumes/nose for a while before /dev/random starts clogging it up again.

Twitter Statistics

Twitter Statistics for caius

Just joining the band wagon in posting up my twitter statistics. The skew towards december being the month I twitter most in is because I enabled twitter sms, and ended up replying/updating a lot more often than I expected.

Published Pictures

Interesting email arrived in my inbox today. I attended BarCamp Leeds in late 2007 and whilst I was there I happened to take some pictures (as I am apt to do these days.)

Anyway, I was rather happy to see that at least one picture isn't just stagnating in my flickr stream:

Hi Caius,

I am delighted to let you know that one of your photos with
a Creative Commons license has been selected for inclusion
in the newly released fourth edition of our Schmap Leeds
Guide:

Town Hall http://www.schmap.com/leeds/sights_hydepark/p=39139/i=39139_10.jpg

Original Picture on flickr

UK Parking

So I just saw this in my twitter stream:

peterc: Warning UK drivers.. councils get powers on March 31st to give you parking fines for infractions they see on CCTV!

This indeed sucks. We'll see how successful they are at ticketing people and whether anyone abuses the system…

Why do I love Ruby?

So mother (who can't program) just posed me the question

Why is Ruby your favourite programming language?

Me being a show off jumped straight into TextMate and banged out some code in real time to show her. First up, a quick little one-liner of Ruby code to output a String:

puts "Hello World"
# => "Hello World"

So she goes, "Sure, but whats so brilliant about that?" So I just decide to reverse the string, have it output in reverse order:

puts "Hello World".reverse
# => "dlroW olleH"

Then the next question comes, "So what makes that so much easier than in other languages?" Well now I was thinking on the spot about which other language I can bang out a quick example in without having to look up too much information. PHP seems the logical choice, being the language I know best behind Ruby.

Thinking about how to do it in PHP, I can't think of a function to reverse the content of a string, but I know that array_reverse() exists, so I just split it into an array and reverse that array. Only problem is I can't remember how to split a string by "", I don't think explode( "", $var ) does the job. So I quickly jump in and write the following code to test my concern.

<?php
  $a = "Hello World"
  $b = explode( "", $a );
  $c = array_reverse( $b );
  echo implode( "", $c );
?>
# => ERROR

The reason for the error is because I've missed a semi colon off the end of line 2, to this I get the response, "well thats certainly not as nice as ruby." Just because one little character is missing!

So I fix the semi colon and run it again, now I get an error complaining about explode not being able to split by a missing delimiter (the empty string - "") So I go hunting through the php.net docs and find str_split(), which does exactly what I want it to.

In replacing explode() with str_split() and running it via the php command line binary, I realise that I haven't got any \n (newlines) at the end of it, so it doesn't display nicely in the terminal. I thus update the script to the following and show her the result:

<?php
  $a = "Hello World";
  $b = explode( "", $a );
  $c = array_reverse( $b );
  echo implode( "", $c )."\n";
?>
# => "dlroW olleH"

And so she goes away seeing why I prefer Ruby to other languages for most programming I do. There are things Ruby fails at (and don't get me started on why rails isn't going to replace php!) and other places where it succeeds very well.

But each to their own, and my own favourite is Ruby!

Update

As pointed out in the comments, if I had looked a bit further I would've found strrev() which does the same as the reverse method in Ruby. So in fact the final code would be:

puts "Hello World".reverse

vs

<?php
  echo strrev( "Hello World" );
?>

So it turns out this was a bad way to show why I prefer Ruby to PHP code wise to mother, think I might have to just bite the bullet and write about why I prefer object.method to method( object )!