Python Programming, news on the Voidspace Python Projects and all things techie.

Jython, the JVM and Apple Macs

emoticon:info Jython 2.2 Beta 2 has just been released. This fixes more than 30 bugs since the last release, and is expected to be the last beta before 2.2 final.

The jump from 2.1 to 2.2 was big, because this is when new style classes came in and the Python object model changes so dramatically. There are two Google Summer of Code students working on bringing Jython up to Python 2.5 [1].

Personally I have no interest in Java and the JVM, mainly because I've never had to program in Java and Java programs that I've used have mainly sucked [2]. There does however, seem to be a big buzz around dynamic languages on the JVM and particularly JRuby. A lot of Ruby programmers come from Java-land. Ruby-On-Rails applications can be developed with CRuby and then seamlessly deployed using JRuby, which may actually be easier than a CRuby deployment. This is the approach taken by Thoughtworks with Mingle. If Jython reaches Python 2.4 or 2.5 compliance, are there any Python web frameworks that could run on the JVM?

Whilst we're talking about the underdog, there is good news for Mac users. Data from the NPD Group reports that nearly 10% of 'retail' notebook sales in March 2007 were by Apple, with nearly 8% of desktop sales. That's far above the current state in the OS wars (a recent report gave Mac OS a 3.5% market share), so things could finally be changing... Just like in the browser wars, healthy competition means that more software will be cross-platform and operating system quality can only improve.

Note

By the way, Seo reports that IronPython 2.0 now compiles with Mono from SVN.

[1]There is also an SOC project to work on the PyPy JVM Backend, which is an alternative approach to using Python on Java. The PyPy solution is much more experimental of course, whereas despite the slow progress with Jython it has been used an enormous amount in production systems.
[2]One exception is Azureus, the bittorrent client which has a great looking user interface.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-11 20:01:38 | |

Categories: , ,


Oh, and Another Thing...

emoticon:cyberpunk Raw strings in Python have some odd quirks. It has long annoyed me that you can't do the following:

>>> r"c:\SomePath\"
  File "<stdin>", line 1
    r"c:\SomePath\"
                  ^
SyntaxError: EOL while scanning single-quoted string
>>>

It turns out there is another restriction. This one is at least for a semi-sane reason:

>>> ur"\u"
UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes in
position 0-1: truncated \uXXXX
>>>

It is so that you can include unicode escape sequences (and therefore non-ASCII characters) in raw Unicode literals. It does mean that you can't create a raw unicode string containing a \ followed by u or U. Smile

Oh, and another thing. I've started helping Mark Rees with the IronPython URLs Blog. He's too busy jetsetting at the moment, so I'm lending a hand. I've also been working on trying to speed up the page loading of this blog by tweaking the javascript. It involves this cute (but ugly) hack from Phillip Pearson, which monkey patches document.write. I can't use it on the adsense or amazon ads, but I should have made some improvement.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-10 23:25:15 | |

Categories: , ,


15 TDD Steps to Create a Rails Application

emoticon:speaker Not the usual sort of thing you find on this blog, but Andrzej has just written a great blog entry on using Test Driven Development to create a Rails application:

The TDD steps are spot on, despite the odd language choice. It's even simple enough that a Pythonista like me can follow it... Wink

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-09 00:06:24 | |

Categories:


Movable Python for Python 2.5.1

emoticon:movpy2 Movable Python has been updated to Python 2.5.1. Is is included in the Python 2.5 and Movable Python Mega-Pack groups.

Movable Python can be downloaded from:

Movable Python is a distribution of Python, for Windows, that can be used without being installed. It doesn't interfere with any Python installation on machines it is used on, and can be run from a USB flash drive. The user interface can be used to launch programs with any executable, you may never need to use the command line again. Wink

Versions are available for Python 2.2, 2.3, 2.4 and 2.5. The Mega-Pack includes all of these versions, and can be used for testing programs with multiple versions of Python (including IronPython) from a single interface.

The new distribution of Python 2.5.1 includes updated versions of the following extension packages:

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-08 16:56:51 | |

Categories: ,


Sometimes Usability Doesn't Count (Plus Some Programming Quotes)

emoticon:animals_cat I've just found the greatest web application ever. Its usability sucks in so many ways, but I'm still hopelessly addicted.

I've just reached January 1999 and Wally has started an internet business. Smile

Whilst we're on the subjective of work avoidance (and believe me we were), courtesy of Jeff Attwood I've found some great programming quotes:

(From Computer Programming Quotes, and some unattributed.)

"Unix is the answer, but only if you phrase the question very carefully."

"The number of the beast — vi vi vi."

"In years past, I knew of someone who used emacs as his login shell, the only thing he found wanting in emacs was a good text editor. So he ended up using vi."

"Java is, in many ways, C++--." — Michael Feldman.

"If I've got a simple task to do (eg the text-file-of-URLS example) then I knock it up in shell script. By the time that simple task has feature-creeped up to more than 20 lines I start to wish I'd written it in Perl. So I rewrite. By the time that Perl script has crept up to more than 200 lines I start to wish it was written in Python. So I rewrite. By the time that Python script has crept up to 2000 lines I start to wish I'd farmed the job out to a team of programmers, and I give up caring what language its written in and make them do it as a web service. Then I write a small shell script to call their web service. When that shell script has feature-creeped up to more than 20 lines..." — Bazman.

"Though I'll admit readability suffers slightly..." — Larry Wall (of Perl fame).

"I would rather use Java than Perl. And I'd rather be eaten by a crocodile than use Java." — Trouser.

"We have a bug that occurs on the 31st of a month so once a month we get a bug report. It gets assigned to a developer within 24 hours who then fiddles for a bit before marking it 'unable to reproduce'." — kosh.

"File not found. Should I fake it ? (Y/N)"

"If brute force doesn't solve your problems, then you aren't using enough."

"My software never has bugs. It just develops random features."

And so on...

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-08 15:37:18 | |

Categories: , ,


Do You Know Your Displays from Your Literals?

emoticon:html Python 3 will see the distinction between the 'str' and 'unicode' types removed. All strings will be in Unicode, and there will be a new 'bytes' type for representing binary data.

The bytes type will be mutable to make it more convenient, and more efficient, to work with them. You will be able to change binary data, or add to it, without creating a new instance as is the case currently with immutable strings.

This means that you won't be able to use standard bytes as dictionary keys, but such is life. You will be able to create bytes objects in your source code using the following syntax:

b"character data
b'\x7f\x45\x4c\x46\x01\x01\x01\x00'

There is an interesting discussion on Python-Dev about whether byte literals in source code should be mutable or immutable.

The problem with making them mutable is that there are places in the Python implementation that might rely on them being constant. One example is the error callback function when decoding: After the callback returns the codec has to recalculate it's variables..

Perhaps a more import distinction, is that the proposed syntax for bytes looks like a 'literal'.

The following code in Python uses a 'literal':

x = 'some text'

The following code uses a 'display':

x = ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't']

The difference, courtesy of Martin Lowis:

a literal denotes the same object every time it is executed. A display creates a new object every time it is executed. (another difference is that a display is a constructed thing which may contain runtime-computed components, unlike a literal).

So if bytes are mutable and also have source-level representation, they should be displays, not literals.

The list display is actually an expression that creates a list when it is executed (runtime), whilst a literal is created at compile time. Currently strings and numbers are literals; mutable and container types have to be displays. So if bytes are mutable, they should be displays - but they look like literals. The solution is to have a mutable and an immutable bytes type, with literals being immutable (and therefore usable as dictionary keys). This has implementation consequences, and the debate continues...

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-07 18:34:49 | |

Categories:


Interesting Links

emoticon:globesearch A few interesting, and Python related, links I've stumbled over in the last few days:

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-07 18:32:30 | |

Categories: ,


One Thing I Hate About Python (Rich Comparison)

emoticon:dollars In recent months there has been a meme going round to write about the 'Five Things I hate About Python'. The latest of these is from Doug Napoleone, and its the best one I've seen so far. A much better meme (in my opinion) is in Taw's The Right to Criticise Programming Languages:

You have no right to criticize a programming language, unless you are able to point three things in which it excels compared to your favourite language.

A while ago I started to write my own list of five Python warts. They were pretty unoriginal so I never published it, but one of my warts was about Python rich comparison. Specifically, the fact that you have to implement all of them, which can be a lot of boilerplate. Worse, if you want equality then you have to implement both __eq__ and __ne__. Having inequality fallback to not equality would serve 90% (more?) of the usecases plus save a bit of typing.

In fact you can deduce all the comparison methods just by providing __lt__ and __eq__. You almost get this for free with IronPython, but not quite. Smile

This article shows how IronPython is different from CPython in this area. It also has a 'Rich Comparison Mixin', so that you can get rich comparison from CPython, just by implementing two methods. There is an example class that uses the mixin; along with unit tests. Smile

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-06 18:29:39 | |

Categories: , ,


Interesting Times on the Internet

emoticon:pen_book It's been an interesting week on the intarwebz. Both the furore over the publishing of the AACS HD-DVD Key and the announcements around Silverlight have caused an enormous amount of comment.

At the latest count, google reports around a million and a half web pages containing the controversial key. Last I heard, the MPAA still claims it is going to pursue every site publishing the key. Yeah right. Smile

My favourite link is the one to a search on the MPAA site. The resulting page has the key showing on their website, I wonder if they'll issue themselves a takedown notice...

As for Silverlight, google currently shows almost one million results for Python and Silverlight. Whatever you think about Silverlight, it's creating a lot of interest in Python.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-06 16:14:50 | |

Categories: ,


Python and Bazaar Events in London

emoticon:globepage There are some more Python related events happening in London over the next couple of months.

There's a Bazaar sprint in London, May 14-18th.

Hopefully they'll find time to have a drinks and talk session. I'd really like to understand the development model that goes with working with distributed version control systems.

There is also a new venue for London Python events, the IET. The first one is likely to be on the 5th July.

Tim Golden comments:

It's a fantastic building, one of those impressive things along the Embankment, next to Waterloo Bridge, and has loads of space for event formal and informal. Don't know yet what kind of arrangement might be made, but at the very least I'd like to see this as the first of some more structured London Python meetups maybe with demos, guest-speakers, etc., firmly allied to the informal London Python drinkups.

Sounds good to me. Smile

More news on the Python-UK Mailing List (and this blog of course...).

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-05 19:49:46 | |

Categories:


They Got Me: A Virus Hunt

emoticon:clock It finally happened, I caught a virus. It's only the second time since I've been using a PC, and it was entirely my own fault. What surprised me was just how much work it was to get rid of it [1].

My usual setup tools could detect the beasty (Smitfraud-C.Toolbar888 apparently), but couldn't remove it. It caused constant IE popups, which would promptly crash.

I normally find the following combination of tools sufficient:

I also tried (both of which are highly recommended) :

The virus was getting itself loaded as a system dll during the boot process, so it couldn't be unloaded and could monitor its files to restore them when the anti-virus tools removed them.

In the end I turned to the guys at Techguy.org who talked me through solving the problem. Many thanks to JSntgRvr who solved it for me. They use a tool called HijackThis to diagnose the problem, and then have a whole battery of tools to solve them.

JSntgRvr also recommended Spyware Blaster to detect further intrusions, but I know exactly how it happened, and it won't be repeated. Smile

[1]Before the Linux zealots start, it was almost as much work as the last few times I've tried to install Linux. Razz

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2007-05-05 19:26:35 | |

Categories:


Hosted by Webfaction

Counter...