Entries from November 1, 2007 - November 30, 2007

Friday
Nov302007

Explicit is Better than Implicit

I have long admired the programming language Python for its simplicity, unpretentiousness and effectiveness. Earlier this year, I came to appreciate this even more when I was able to use it in a project at work.  On several occasions I ran into what appeared to be insuperable problems only to discover that Guido (van Rossum - the designer of Python) had been there before and had provided a minimalist, practical solution.  It really was a pleasure to use.

However, there have always been a couple of very basic things which I feel that Python has got wrong.  These are not so much problems for experienced programmers, who can easily work round them, as they are for beginners, who almost always trip up over one them.  They seem so unneccesary and it worries me that they are still there, to the extent that I always hesitate before recommending Python as a beginner's language.

The first is using leading zeros to indicate octal numbers.  For example: 101 = 101, 110 = 110, but 011 = 9. This feature appears to have been inherited from C.  Octal is more or less extinct now and, for those applications that need it, it would be far better to have an explicit indicator rather than this underhand subterfuge from the dim and distant past.  Python should at least have a command-line option to allow you to choose whether you want it or not.

The second problem arose yesterday when my daughter was doing her maths homework.  She had some calculations to do involving numbers raised to various powers but couldn't find her calculator so I suggested that she use Python.  She typed in something like (1/4)**2 and got the answer 0, which is not what she was expecting.  The problem is that in Python the symbol '/' represents two different operations according to the types of its operands.  If one or both of x and y are floating point numbers then x/y respresents a floating point number approximating z such that x = y*z.  But if x and y are both integers then x/y returns an integer n such that n <= z < n+1 where x = y*z.  This 'integer' or 'floor' division is a completely different operation from normal division and it should (again) really be represented by a different notation.  Fortunately, another notation already exists in Python: '//'.  However, if you want '/' to represent proper division you have to make it explict that at least one of its operands is a floating point number and the best way to do that is to use the float() constructor: float(x)/float(y).

I wasn't about to explain all that to my daughter (and she wouldn't have listened anyway), so I told her to use the Ubuntu calculator, gcalctool, instead.  This has a scientific mode in which she was able to enter (1/4)^2 and get the right answer, 0.0625.

(The title of this post is taken from Tim Peters' Zen of Python.)

Thursday
Nov292007

Teddy Bear Protest

I can't help feeling that the appropriate way to protest against this would be to send teddy bears to the Sudanese embassy.  A cuddly toy would make a good symbol of protest against religious bigotry.  It projects the right image for deflating pomposity without being threatening.

Monday
Nov262007

Rejecta Mathematica

rejecta-mathematica.gifWhen I first read of  Rejecta Mathematica, I felt sure it must be some sort of joke but, apparently, it is not.  However, I am sure it will be treated as one all the same.  (Via Science at Sunclipse.)

I note that their web-site is math.rejecta.org which suggests that, if the journal is a success, then we might see phys.rejecta, astron.rejecta and so on.

Saturday
Nov242007

Anglo-Saxon Jewellery in East Cleveland

anglo-saxon-jewellery.jpg

This summer my daughter Zoe stayed with my father at his home in Cleveland (UK).  One day my father took her to visit a local archaeological dig.  When they got there, a friend of his who was working there as a volunteer, showed them a gold brooch with inlaid precious stones that he had just that moment excavated from the ground.  He was understandably rather excited. 

The dig was the Anglo-Saxon burial ground near Loftus.  This burial ground was discovered by local archaeologist Steve Sherlock from aerial photos.  The excavation, also supervised by Steve, was carried out in some secrecy over the past three summers but has now gone public.  See here, here and here for more details.  There is some speculation that one of the burials might be associated with Ethelburga, wife of King Edwin of Northumbria.

Monday
Nov192007

Perpetuum Mobile

This evening Zoe was looking up some Latin phrases when she came across perpetuum mobile.  We both agreed that it should mean "always talking on the phone".