Python Programming, news on the Voidspace Python Projects and all things techie.
Static Typing - in Music
Following on with the theme of taking the micky out of static typing , I've found the perfect band for those who love statically typed programming languages :
The Incredible Mouth Band
Actually one of my colleagues showed this to me, but it's still funny.
|||Don't take this too seriously Max.|
Python in the Corporate World
It looks like Joel Spolsky was right: Python Interview Questions
We've finally made it.
Hard Drive Wisdom on Windows from Python Newsgroup
Every now and then you stumble across an unexpected nugget of wisdom on the Python newsgroup, comp.lang.python
Did you know that the default setting for hard drives under Windows puts your data more at risk of data-loss than it need be ? (I can hear Nicola Larosa grinning already.)
Russell Warren and friends explain :
A file system journal is used in order to guarantee the integrity of the file system itself (but not of each individual file). Systems using NTFS are known to have improved reliability compared to FAT file systems.
However, by default, hard drives have write-caching enabled. This means that in the event of a power failure data may not be written to disk.
You can verify this by going to the device manager, right click on the icon of your hard drives and select properties. Normally 'Optimize for Performance' is selected, which enables write caching. If you don't have a UPS or backup power source, you may want to disable this.
My apologies for the rash of short entries, normal service will be resumed whenever I can be bothered.
IronPython and Hashlib
Seo Sanghyeon has been at it again. He has just wrapped hashlib for IronPython.
This module implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512 (defined in FIPS 180-2) as well as RSA's MD5 algorithm.
Of the implementation Seo says :
You can read the source, but here are some technical details:
In CPython, hashlib is backed by OpenSSL. hashlib.new can create hash object by name, in contrast to static constructors like hashlib.md5. This is implemented by OpenSSL function EVP_get_digestbyname.
I have mapped this to HashAlgorithm.Create, which was an obvious choice. This can be used, for example, to load RIPEMD160 which doesn't have static constructor in hashlib.
Oh, by the way, I updated hash_test.py too, and you can see the usage there. hashlib import is conditionalized to make it run on CPython 2.4 too.
Mono.Security.dll implements the SHA224 algorithm. This assembly is always included with Mono (as many security tools depends on it). The same assembly/binary can also be used on the MS runtime without any problems. (Now included in FePy.)
Very cool, but although FePy is a clever name, it isn't easy to say without it sounding faintly girly. Hmmm...
Some Things You Just Have to Share
The problem with geek jokes is that can be very hard to find someone to share them with. Luckily that has been much easier since I started work at Resolver, but I also have this blog.
If you've not come across xkcd before, they can be very funny.
IronPython Version Info
How does an IronPython program tell which version of IronPython it is running ?
Lots of code uses sys.version and sys.version_info to determine availability of Python features so changing that seems like a bad idea.
Also, the IronPython dlls are signed. So in order to allow updated dlls to be 'drop in replacements', the IronPython team keep the same assembly version between different releases.
So in 1.0.1 they added some assembly level attributes. This means that (currently) the official way to tell from code which version of IronPython you're running on, looks like this :
attribute = System.Reflection.AssemblyFileVersionAttribute
dotnetType = .GetType()
a = dotnetType.Assembly.GetCustomAttributes(attribute, False)
if len(a) > 0:
if a.Version == "1.0.61005.1977":
print "IronPython 1.0.1"
print "Unknown version"
print "IronPython 1.0"
I hope they add a new attribute to sys, or some other sensible solution.
Jan Szumiec: May he Blog in Peace
Sorry for the obscure title, it's been a long day. Added to which I've just got home to discover that our front door has mysteriously dead-locked itself and I had to break in. Luckily I met my new neighbours in the dead of night last week, so they recognised me and let me round the back of the house. sigh
Anyway, Jan Szumiec (one of our summer interns at Resolver ) has just gone back to Poland. Despite his penchant for Ruby and Smalltalk, he is a clever guy and we will miss him. If he doesn't come over to work for us again at Christmas, I'll catch up with him at the RuPy Conference (Ruby and Python) in Poznan next April.
I've been meaning to link to his blog RubyRed for a while now, so there you go. As you can read from his recent entries, his experience at Resolver has thoroughly converted him to the merits of test driven development.
I read somewhere a plausible explanation of why Python and Ruby are such contentious bedfellows (which makes the RuPy conference all the more interesting IMHO). It's because they are so similar. Competition is the fiercest between organisms that share the same evolutionary (or environmental) niche. Because Ruby and Python are both good for a similar range of tasks, they compete for mindshare and programmers.
Luckily Python is well established in areas other than web development, so even it really does 'lose' to Ruby it isn't going to go away. phew
Two other pieces of unrelated news to shoehorn into this post.
- There is a new blog aggregation called London Python. This is a Planet collection of London and UK Python bloggers.
- The Python 'trunk' has just been frozen for a new release in the next few hours. This will Python 2.4.4, which ports many of the bugfixes incorporated into Python 2.5 back to Python 2.4.
|||Yes the website is going to get a makeover, 'real soon now' to channel my boss.|
New Things with IronPython
IronPython 1.0.1 is now out. One of the new features is that it now supports new 'builtins' through 'external' assemblies (dlls).
Tangible Software Solutions also have a new product out :
This is a VB.NET to IronPython translator. I have a copy to play with, so if anyone can suggest a good project to experiment on with it, I'd love to hear about it.
rest2web Man Page
I'm trying to push out a new release of rest2web this week, hopefully in time to get it into the forthcoming release of Debian.
There are a few outstanding issues and some easy feature requests that I can complete, but finalising the documentation updates for 0.5.0 final.
The fly in the ointment is that I won't have time to create a manpage for rest2web, which is needed for inclusion in Debian. I can write the text necessary, but don't have the time to learn a markup format and prepare it in time.
Is there anyone who might be able to do this for me, if I create the 'content' ?
Agile Development & Religious Wars
Sometime ago Joel Spolsky linked to some guy's blog entry that was knocking Agile Development as a fad, or something like that. I didn't pay much attention, because Joel doesn't seem to think that functional testing is even possible so I doubt he has much sensible to say on the subject (or by implication is capable of linking to anything sensible...).
Anyway, it turns out that Steve Yegge was probably just saying that it has become another religious war. I still haven't read the original post, but because I have too many things to do and need a distraction, I skimmed his latest entry.
I can't tell you much about it, but there are two parts that are really funny.
Firstly (talking about the Perl Haiku Competition) :
I tried it with Java once, and produced a valid Java haiku:
ArrayList<int> myListOfInt = new ArrayList<int>();
which, spoken aloud, reads:ArrayList of Intmy list of int, equals newArrayList of Int
Maybe it's just me, but I find it pretty farging depressing that a simple declaration like that can be haiku-sized in Java.
Secondly, he talks about static type systems :
The noted Far Side cartoonist and computer scientist Dr. Gary Larson published the definitive paper on Java-style static type systems in October 1987. [...] Here's Dr. Larson's renowned treatise on non-inferring static type systems:
Very funny. Mind you, having read a bit more of his post in the process of typing this up, it would appear that it is a crock of horse manure. I can't really tell as he doesn't seem to define 'agile methodologies' at all in the bits I've read, so I don't really know what he's talking about.
If he's just saying that religious wars are dumb, then I think I agree with him.
I now work with a company that use a whole raft of 'agile development' techniques. It's great. The process is fun, pair programming means you're less distracted so you produce more, and the code quality is great. I now use the relevant parts for my own projects (TDD etc), where possible, because I can see that it produces better code. In my experience these techniques are better than the alternatives I've seen. That's just my experience though.
It reminds me of the whole virulent creationist versus virulent anti-creationist thing. I'm a christian (if I don't put a capital C am I being blasphemous or something ? I just don't know these things). That whole debate is utterly irrelevant to me, as are most theological debates and arguments. My own faith is based on experience of God and relationship with him (I'm pretty sure that capital-G is right), so arguing about it is pretty damn pointless in my book. I'm not into proving God to people, but if they're up for it I enjoy helping them experience God . Oh, and on the creationist thing, I think that I think that something a bit like intelligent design is probably right. But I don't really care, it's not the cornerstone of my faith.
|||For those who may be interested, I just made a post which is vaguely about the substance of my faith on my personal blog.|
Devil in the Detail
You can always tell a sloppily written program. When something goes wrong, you will get a helpful error dialog (if you're lucky) saying something like :
An Error Has Occurred
This morning, Christian and I have been adding some nice straightforward functionality to Resolver, at the tail end of a fun User Story. It may be straightforward, but as ever, the devil is in the detail.
There are lots of different ways this feature can fail, depending on exactly which permutation of munged input our user provides. We're going through and catching all of them, and providing sensible error messages. I'm feeling the pull of the dark side, but have so far managed to resist the An Error Has Occurred dialog.
Is CGI Dead ?
With the recent rise of web frameworks, like Ruby on Rails, Django, Turbogears and friends, it might be fair to assume that the old workhorse CGI can be put out to pasture.
CGI is a simple protocol that describes how a webserver passes http requests to a program, and how that program makes a response.
The beauty of CGI is it's simplicity. Most of the request  is passed on stdin, and the program passes a response back to the server on stdout.
The Python CGI Module makes understanding http requests very easy. To send a response, write to stdout.
CGI is still a very good way of connecting simple programs to the web. It's also a great way of cutting your teeth with web programming, particularly learning about http. In fact WSGI (the new Python protocol that aims to allow components in a webstack to communicate) aims to be a modern evolution of CGI.
Quite sophisticated programs can be written as CGIs, but they are more inefficient than modern web frameworks, as each request is handled by a separate Python process.
I've hacked around with a few CGIs of my own. I've also written a couple of tutorials, if you're interested in learning :
|||Ok, so I'm a bit late with this entry.|
|||But not authentication headers unfortunately.|
Zlib for IronPython
Seo Sanghyeon has just announced that he has implemented zlib for IronPython (based on work by Mathieu Fenniak).
Here is what he has to say about the implementation :
|Done:||adler32, compress, decompress|
|TODO:||crc32, compressobj, decompressobj|
At first I was confused because data compressed with Mathieu's code couldn't be decompressed with CPython's zlib module and vice versa.
People on #mono channel helped me. They told me .NET's DeflateStream is "bare" in that it doesn't generate nor accept ZLIB header and footer as defined in RFC 1950. So after reading the spec, I just wrote that part myself.
It still doesn't generate identical output, but compress/decompress in any mix of CPython/IronPython seem to work. I didn't test the code on Windows yet, so I'd appreciate your comments.
There is now an experimental version of Movable IDLE available, this is an off-shoot of the Movable Python project.
Movable IDLE, version 0.1.0 can be downloaded (free) from :
(Same place as the trial version of Movable Python.)
Movable IDLE is a portable distribution of IDLE, the Python IDE, for Windows.
This can be run without installing, and at only fifteen megabytes uncompressed it can be run from a USB stick or memory card.
It comes with the full Python standard library, and should be capable of running almost any program that can be run with IDLE. Hopefully this will be useful for educational and experimental purposes.
Movable IDLE doesn't yet have a homepage. This will be part of the new Movable Python docs, which I'm still writing.
Movable IDLE does not have all the clever trickery that Movable Python does. This means that the win32 extensions, or any program that uses imp.find_module are unlikely to work. It also won't work with programs that have another event loop, like other GUI toolkits.
If you need these features, try Movable Python.
On the other hand, if you do find bugs or restrictions, post them to the Movable Python Mailing List and it may be possible to fix them. This is the right place to post feedback and suggestions as well.
Movable IDLE is copyright Michael Foord, 2006. It is free, but not Open Source.
You are free to copy and distribute Movable IDLE, but not to charge for it. It may not be included in any distribution which charges directly or indirectly, without express permission.
The following sections of the Movable Python License also apply :
- Restricted Uses
I forgot to mention that this was originally inspired by an email from Calvin Spealman.
In case the version number doesn't make it clear, this is 'experimental'. I'll fix any problems that arise (assuming I can fix them).
Voidspace Server Move
After sticking with the same host for around a year (almost a record for Voidspace I think), I've changed server again.
Instead of having root login on my own virtual server, I now have a Shared-2 Account. Although technically I can do less with this account than I could before, I don't have to maintain my own server. On top of this, deploying dynamic applications from Webfaction looks very easy. At some point in the next ten years I hope to find time to play with Django or Turbogears.
Setting everything up was pretty straightforward (with a bit of help from Remi), for the several domains and email addresses I've moved over there. The only hiccup was a bit of time trying to work out how to point both voidspace.org.uk and www.voidspace.org.uk to point to the same place. Realising that the list of subdomains in the 'website' part of the control panel supported multi-selection was a big help.
I had some fun with my CGI scripts. It seems that Apache running CGIs with SuExec is pretty finicky about permissions. Additionally, the Webfaction servers don't have sendmail. I've changed a lot of my scripts to use smtp  rather than sendmail (resulting in a minor bugfix to my contact form CGI).
Unfortunately I still have an authentication problem.
Changing server always causes problems, so I've come off quite lightly. Currently my contact form is down and I lost a few days worth of stats on my page views. Not too bad.
|||They use cgiutils, which has code very similar to the example show in the Webfaction email FAQ.|
This work is licensed under a Creative Commons Attribution-Share Alike 2.0 License.