Archive for March, 2007

Some computer jokes

Friday, March 9th, 2007

A friend at uni who wanted me to fix her "cd rom" … I said I'm most unlikely to be able to help you fix some laser- and radioactive-based device, but she insisted. It turned out she hadn't plugged her computer in. I said well why did you think only the cd-rom didn't work? She just said "i call the whole thing the cd-rom!" as if there was nothing wrong with that.

I have found people often say "what virus program should i use?". As opposed to anti-virus program.

A friend spilt apple juice over her keyboard of her notebook and rang up the tech support and they said "what type?" or something presumably refering to the notebook and she said "natural apple juice.". I think she has a Ph.D. in Computer Science now, and had a Masters then.

All of these are in fact not jokes, but real stories!

Floats and Doubles

Friday, March 9th, 2007

C has the types "float" and "double" (normally 4- and 8-bytes long). Java has them too (but their length and behaviour is exactly defined in Java). PHP also has "float" and "double". Most people only ever program with doubles.

I always wondered where this concept of having two exactly-sized types came from. Databases allow yo to specify precision and scale to suit your application.

I always assumed C introduced this, and every other language copied it (like many other features, such as for-loop syntax). But maybe it was Fortran?

http://www.php.net/manual/en/language.types.php#43671

Keep your options open

Thursday, March 8th, 2007

I once saw an episode of "cops" where the police officer kept on telling the offender, "your license has been suspended or revoked!" like that officer was not allowed to modify the standard phrase and inform the offender which of the two events had in fact taken place.

That's a bit like software telling you you have "1 file(s)".

I was forced to think of the above when I saw the following error message after trying to open a file in Word:

Store currency amounts as number of cents, pence, etc.

Thursday, March 8th, 2007

The way numbers are stored in C and thus in PHP, Perl etc., and also Java, is with a binary system. So if you have 2 it's "10" in binary, 5 is "101" and so on. And the same is true for fractions. So a half is "0.1" and a quarter is "0.01". That means that just like "one third" is not exactly representable in our decimal system (0.3333) numbers like "one hundredth" which are easy to represent in decimal cannot be represented exactly in binary.

Oracle and the MySQL "numeric" type stores data as decimal. Meaning if you store "a third" to two decimal places, they get stored as "0.33". And if you try and add 3 "one thirds" together you get 0.99 not 1.00.

So those Oracle/MySQL data types, using decimal, are good for representing money, as you can exactly store "one hundredth". And adding 100 "one hundredths" gives you 1.0 exactly. However that doesn't help one much, as all programming language in common use today only support a binary floating-point representation - which can't store "one hundredth" exactly.

This is more of a philosophical issue than a piratical one. Because even if one does add 100 "one hundredths" together, one gets a result like 0.9999 and if one tries to print that to two decimal places, then rounding will take place, and "1.00" will be displayed, i.e. the right answer. So it's not really a practical problem.

However, the solution to the problem is easy to implement: just store a whole number of cents, pence, etc. So there's no reason to accept any inaccuracy when it comes to storing monetary amounts.

This was the way my Mother programmed, when she had to deal with pounds, shillings and pence in the old UK pre-decimalization monetary system: she simply stored the number of pence as an integer. If it was good enough for her, it's good enough for us now. After all, software development doesn't change that much over the generations.

"Smith Software Development (Macau) One Person Limited" exists

Thursday, March 8th, 2007

I went to a meeting today where my company was officially signed and documented into existence.

VCS Commit emails are good!

Wednesday, March 7th, 2007

I am currently working on a small project with one or two other people. We don't sit in the same office (or, right now, on the same continent or in the same timezone).

Every time something is committed into our version control system (Subversion), everyone on the team gets an email. This lists:

  • The files which have been changed (or added or deleted)
  • The commit log message, i.e. written by the programmer, explaining what the commit represents
  • A "diff" of all the files which have been changed

I read all these emails, and it's really great to get a feeling for what's going on in the project. It's one extra communication medium, on top of the normal email, IM, telephone, wiki, task lists, and so on.

I don't know how this would work in a larger team, but for our small team it works perfectly.

My father once told me a story about a boss of some company he had worked at, who read all the faxes which went out and came in to his company. He said that was the only real way to actually find out what was going on in the company. Reading commit logs is similar!

I know a lot of times people omit information because they assume you already know, or they just forget. When I look back at communication failures on projects I've worked on, a number of them wouldn't have occured if a similar system had been in place.

Making changes to a Script

Wednesday, March 7th, 2007

I need to change a bunch of functions in a bunch of classes to take a "user" object as opposed to a "user_id" number.

I am using a scripting language. How am i going to do this? I am going to do it the best i can, then compile, but the compiler is not going to find any problem as they are the same "type" i.e. they are both values.

Then i'm going to get lots of runtime errors. I'll correct them until they all go away. Then there will be no known runtime errors. Which is better than known runtime errors. But both more difficult and much less satisfactory than a simple compile in a language like Java or C++ which would find all occurances of such errors.

Thankfully I have lots of unit test scripts which will help in my unnecessary debugging process. A lot of them I just wrote to test simple things like "do getters work?". In a compiled language many of those tests would be unnecessary as the only errors that could occur, the compiler would pick up.

So scripting languages have caused me more effort:

  1. To do and test this change
  2. To write and run and maintain unnecessary unit test scripts
  3. To write this blog post (which wouldn't have been necessary had points 1+2 not been necessary).

Job advertisement

Monday, March 5th, 2007

The following job advert appears today through Wednesday in the Macao Daily News. This is my first ever advertisement in a newspaper reading back to front!