Monday, May 25, 2009

Grandma errors.

After having checked for splling errors, it can be good to check for grandma errors.

'In linguistics, grammar refers to the logical and structural rules that govern the composition of sentences, phrases, and words in any given natural language.' - wikipedia (writer Hannes Hirzel is listed as the oldest writer for the Grammar entry on wikipedia... an entry with many many many hundreds of revisions).

So why "grandma errors" and not grammar problems?

Firstly grandma is a word spelt correctly... however used in that context is incorrect. It is a grammar problem itself.

It also sounds like grammar. So it's a self describing word illustrating itself with a meaning completely different to what it is supposed to be used for.

I use "grandma errors", rather than "grandma problems"... because "grandma problems" is used more often when people discuss problems with their grandmas. If someone says they have grandma errors.... and are talking about their mums mum, then they are some sort of star trek nerd that has one room in their house devoted to star trek collectibles, or perhaps a robot.


So have you checked your writing for splling and grandma errors?

Colourless green ideas sleep furiously.

Tuesday, May 19, 2009

Pythons float makes me want to smoke crack.

Ran into another annoying bug with pythons 'float' numbers today, and it reminded me of an old post about how Decimals should be default in python3.

Witness pythons supreme silliness printing out time.time()...

$ python3 -c "import time;print(time.time())"
1242730404.02

$ python2.5 -c "import time;print(time.time())"
1242730412.33

$ python2.6 -c "import time;print(time.time())"
1242730416.87

$ python2.6 -c "import time;print(repr(time.time()))"
1242730432.5543971

$ python2.6 -c "import time;import decimal;print(decimal.Decimal(str(time.time())))"
1242730432.55



Notice how it truncates the float to only two decimal places?! So silly, and likely the cause of many subtle bugs in programs throughout the land. If you repr it, there are less places cut off (12 for print vs 17 for repr).

The last example shows the real bad part... say you want to use a decimal... python strangely wants your argument to decimal be a str, not a float. Then your float gets truncated by the str() function... and BAM!! POW!.


The problem with pythons decimal.Decimal(1.0) is that it gives you this error message if you pass it a float...
TypeError: Cannot convert float to Decimal.  First convert the float to a string


Peoples first response is to do... decimal.Decimal(str(123456789.12345670))... BAM!! POW!... you just truncated your number, and lost precision(and accuracy).

Many pieces of code make this mistake with pythons silly float handling.


Decimals are not as silly as a python float for printing:

$ python2.6 -c "import time;import decimal;print(decimal.Decimal('%23.23f' % time.time()))"
1242732616.70742297172546386718750


Note the "%23.23f" which says to use up to 23 characters on the left, and up to 23 on the right. So if you want to print, or str() a float... and expect something sensible to show up... don't use print(afloat) or str(afloat) or even repr(afloat)... use that weird syntax instead (with appropriate precision chosen on each side)!



The Cobra language(which Simon wrote about recently) does use Decimals by default - and it has many other elegant features.

Friday, May 15, 2009

Some ubuntu love... ♥

Really enjoying Jaunty!

There was only one slightly annoying issue with the graphics being slower (now fixed for me). I have since learnt that there's some very good speedups coming in the next linux kernel too - since a lot of the intel video driver has moved there now. This means it will reuse a bunch of the highly optimised memory management code and also be maintained as the kernel is maintained... meaning less problems. It also means that the driver can be optimised by very good kernel hackers, and the X and framebuffer drivers can use the same code.

My wacom tablet is now autodetected... and works with touch sensitivity without it being plugged in at the beginning. Means I don't have to remember to plug it in before I start X... and no configuration needed either.

The trackpad is working much nicer, and does not misbehave :)

There is a standard kernel, a low latency kernel... and a realtime kernel all apt-get able! The realtime kernel is really nice for sound/music/video/game apps. Better than anything available from windows/OSX.

Copy/paste in gvim seems sane :) Yes! (It has the best copy/paste of windows/OSX/linux for a programmer).

Resizing my ext3 HD was quite simple... so I regained an extra 100 gigabytes which was unused on it. It resized it live - whilst I was still using it :)

Using an extra monitor is now very nice. Better than my experiences with OSX/windows. Since I can tell Ubuntu where my monitors are in the real world... so if I have one up high and to the right - when I drag a window between the two, it looks to be in the correct position physically. Also the resolution on my external monitor is the full resolution - better than what the windows driver can do.

Python2.6 - 64bit optimized (4x faster python than something like the 32bit python2.5 that comes with the latest OSX). Lots of recent python modules all apt-get able :) One of the best - if not THE best system pythons around. If you love python, you'll love ubuntu - you can also install multiple pythons at once really easily. So I can have 2.5, 2.6, and 3.0 all installed at once, without any hassles.

A whole bunch of little things have been tweaked and polished.

Haven't had a chance to check out lots of audio stuff yet... it'll be interesting to see if they've improved that at all. Will report back on audio findings soon.

Unfortunately they broke joystick support at some point... here's the ubuntu SDL joystick bug report.

Monday, May 11, 2009

bundling testing with your program... Ubuntu does too with Jaunty.

Ubuntu, with the latest release Jaunty, has a new application called "System Testing" which allows users to run system test.

The program is called checkbox, and you can run it by selecting it from the menu:
    System -->Administration-->System Testing
Now it's not a bunch of unittests... but instead it is a bunch of interactive tests. It's written in python too.

It asks you some questions, and you need to perform the tests manually, and tell it if things worked correctly.

At the end you can send the test results and the details gathered to the Ubuntu hardware database if you choose.

As mentioned in 'pygame.test - moving testing forward', 'pygame.tests and pygame.examples as packages' and 'Distributed testing - the easy way.' installing tests with your program lets way more people test your shit.

So why not join numpy, cherrypy, pygame, ubuntu and others in installing tests with your program or package?
    >>> import yourpackage.tests
>>> yourpackage.tests.run()

python -m yourpackage.tests
Why hasn't python started to install it's tests so that everyone can run them... not just developers? Maybe jython, pypy, or ironpython will be first.

Update: as Marius in the comments suggests... 'python -m yourpackage.tests' is nicer than 'python -c "yourpackage.tests.go". Also it appears python has installed it's tests afterall... I did some digging, and if your packager has installed them... you can run CPythons tests with
    python -m test.autotest

python3, and symbian(nokia phone) branches merged into pygame trunk

Over the last week two branches merged into the pygame trunk.

Lenard Lindstrom got his python3/python3.1 branch merged in.

Jussi Toivola had his symbian_s60 branch merged in to trunk.


Both ports do not have complete functionality yet... but both have most major modules working.

The python3 code has also been tested with the python3.1 beta release (there are small C API differences between both). Some of the work was based on stuff done by Marcus for his super-cool pgreloaded branch of pygame (which he is going to start doing some pre-releases of soon).

Pre-release builds for both pygame-python3.0, and pygame-symbian_s60 are available... search the mailing list for details. Both also build from subversion trunk.

Lenard got the python3 stuff ready quickly for a course a teacher is doing teaching python3 - part of the course uses pygame. So the pygame should work for his class.


We are hoping to release pygame1.9 in 3-4 weeks. Which means that there's about 1 week to get any last minute changes in. If they are new features, we will require docs/example, and tests... and it's probably too late to add any big features with an API larger than a function or two(unless the API has been discussed on the mailing list already).

The pygame1.9release is timed this way, so that we can get a release out around the time the GSOC coding period officially starts. The GSOC students can be involved in a release, and we can devote more time to their new projects after the release is out. We should also have a good version ready for python3.1 whose release schedule says it is to be released in 6-7 weeks (June 27th).

If any python3 developers want to help us improve our python3.1 support - please get in contact with the mailing list.

Saturday, May 09, 2009

SHA-1 - fail.

As some people have been saying for a while now, SHA-1 has reached it's end of life.

Summary of the paper: SHA-1 collisions now 2^52 (pdf) by Cameron McDonald, Philip Hawkes and Josef Pieprzyk, Macquarie University and Qualcomm, Australia.

More details about how Debian and openpgp are moving away from SHA-1.

So if you're still using SHA-1 (or md5!) time to move onto the next one... SHA-2.

Friday, May 01, 2009

pygame 2001-2009(8 years), 1100+ projects at super speed.

I have put together a video representing some of the pygame work out there.

Enjoy!
http://www.youtube.com/watch?v=Qu2Tuo3HPbo