inicio mail me! sindicaci;ón

Archive for August, 2006

Django from another perspective

We all know Guido (and others) really like Django but this post has been conceived to emphasize a different opinion about this framework. The author of the quote is Antonio Cangiano, the man behind IBM DB2 Tools for Rails, so not exactly a fellow Pythonista. Here you are:

The template system allows designers to define the UI without having to know how to program in Python. This is a key point. DHH has the opposite philosophy: “My perspective is that designers won’t be creating templates from scratch anyway. Not unless they more or less become programmers.”. I disagree. I recently worked with a brilliant artist, who is a talent web designer but did not have any experience with Ruby or Rails, and this affected the “agility” of development because she couldn’t just focus on her job, she had to get a bunch of Ruby/Rails skills through out the process;

You can find the full post here: Django is great

XAML puzzles me

As a former .NET developer (ok don’t tell it to mama!) and Italian native speaker I can amuse myself not only with the strangeness of the anglo-saxon community but with the Italian community’s also! That doesn’t sound like a privilege, though. Gotta rewrite this paragraph one day.

We have the biggest .NET user group in the world as far as I know with thousands of subscribers and MS Italy endorsement. This community has a blog aggregator like our Planet Python and yesterday I went through a post that puzzled me a bit.

The title of the post is (translated): XAML: is it worth the effort?. The Italian .NET MS MVP named Corrado Cavalli responds to his reader making the point about the brand new XML format to handle application user interfaces in .NET. The answer is, obviously, yes but let’s see what I get (with my “pythonized” eye) from it with a F-A-K-E conversation:

.NET Lover: XAML is cool, but by now you have to hand write the GUI in XML. Lawrence: no way dude, XML is for the machines, not for the humans. Look at what happend with that shitty specification named SOAP and all the WS-* bandwagon. XML is good because is text and machine readable. Glade and Gazpacho, our designers of choice spit out XML from the dawn of the world. GTK, QT, Cocoa, you-name-it. Everybody has an interface builder!

.NET Lover: Believe me Lawrence, you don’t get it, there are at least 2 Microsoft interface builders but, hey, at the 1.0 version they will be incomplete. Lawrence: Fine to me, I hope someone will explain the meaning of alpha, beta and 1.0 to MS engineers one day. Anyway, so now we have not one, but two builders! You said I had to struggle with angle brackets all the day to do the hello world demo. You liar!

Read the rest of this entry »

A bit of PyPy in the realm of Zope

The first day of the EuroPython PyPy sprint I happened to start my bird view acquaintance with a guy named Brian Sutherland. He decided to attend the sprint to try make a bond between Zope world and PyPy’s. We also paired together a bit and that was cool.

He now published the results of his efforts of porting zope.interface.adapter.LookupBase but sadly the ultimate response was: In retrospect the choice of module to re-implement in Restricted Python was not a good one.

I’m also agree with his conclusion about the greatness of PyPy and its problems. So check this out: Investigation into using PyPy’s Extension compiler with Zope modules

Rails, ActiveRecord, benchmarking and why I feel evil

I feel evil tonight (here is 3:30am) and then the fortune brought me to the /benchmark directory in ActiveRecord repository (for who doesn’t know what ActiveRecord is, and I think due to the hype everyone knows, see Wikipedia ORM page.).

A while ago someone slapped us with some bench between Rails, Django and Symphony and guess what: Django won hands down. What does it mean winning with raw numbers? To me not much but winning fairly is better than losing cheating. The thing I liked most in that bench page was not the bench itself but a comment at the end:

When connecting rails to Oracle the performance dropped to the extent it made any production use of the product useless.

That sentence is evil because recalls me words like enterprise, enterprisey and whatever that most of the time make me smile.

So, about benchmarks and being evil tonight. ActiveRecord trunk repository has two files in the so-called benchmark sub-directory with two benchs. This:

  1. ActiveRecord::Base.establish_connection(:adapter => “mysql”, :database => “basecamp”)
  2.  
  3. class Post < ActiveRecord::Base; end
  4.  
  5. RUNS = ARGV[0].to_i
  6.  
  7. runtime = Benchmark::measure {
  8. RUNS.times {
  9. Post.find_all(nil,nil,100).each { |p| p.title }
  10. }
  11. }
  12.  
  13. puts “Runs: #{RUNS}”
  14. puts “Avg. runtime: #{runtime.real / RUNS}”
  15. puts “Requests/second: #{RUNS / runtime.real}”

and

  1. conn = Mysql::real_connect(“localhost”, “root”, “”, “basecamp”)
  2.  
  3. RUNS = ARGV[0].to_i
  4.  
  5. runtime = Benchmark::measure {
  6. RUNS.times {
  7. result = conn.query(“SELECT * FROM posts LIMIT 100″)
  8. result.each_hash { |p| p[“title”] }
  9. }
  10. }
  11.  
  12. puts “Runs: #{RUNS}”
  13. puts “Avg. runtime: #{runtime.real / RUNS}”
  14. puts “Requests/second: #{RUNS / runtime.real}”

Let the code and my evilness speak for itself, it’s not time to be sarcastic.

Modules on Windows and last bits of Summer Of Code

I just commited the last lines to make mmap module compile as a shared library (DLL) on our beloved Windows platform.

I first tried porting my implementation of time module to Windows and it was a lot easier than I thought. Ok… easier… let’s go back a moment. I have to be fair to myself and you reader so I have to summarize what you should to achieve the same goal to make PyPy’s modules toolchain work in Windows:

  • install MS .NET 1.1
  • install MS .NET SDK 1.1
  • install MS Platform SDK for Windows 2003 Server (I have XP in Parallels, but there’s only that available)

After this giga-byte-loola-palooza-taking-ages-to-install you go underground this way:

  • ’search’ and download the MS Visual C++ 2003 Toolkit that MS kindly retired from its download center after telling everyone it was free for everybody. (I still don’t understand why the biggest company in the world can’t let somewhere in a repository its old packages. I can give you some webspace MS, call me!)
  • hack (I mean H-A-C-K) distutils to make the dream come true. Thank you Mike Fletcher!
  • inject basically every \bin, every \lib, every \include in my entire file system into the batch file. (I always hated DOS batch files, even when I had only DOS 3.0 on the computer. Come on MS, show me what you got!)
  • last but not least: cross your 20 fingers. (remember my fellow Jedi, also the feet have fingers)

I forgot to mention that this easy procedure worked eventually and I was really happy the way things gone. I still hope Martin von Löwis will change its mind sometimes about sticking with the 2003 version of the MS C++ compiler but now that I mastered it, it’s not that urgent.

The implementation of time in Windows lacks altzone, tzname, daylight and timezone because of some limitations in PyPy (I can’t use in_dll() to export global variables) but everything else works well. The other module, mmap, should be equal to the POSIX version.

My Summer of Code project is basically finished and I’ll surely post a report of my experience after the official deadline.

startswith() and endswith() in JavaScript 1.5

MochiKit is a great JS library but JavaScript itself kinda sucks at string manipulation (if you’re a Pythonista it sucks a lot).

While I was fixing and improving the features of a web application I ended writing awful code to check if some string was at the beginning of some other string. I, then, decided to write a JavaScript version of Python’s startswith and endswith.

The two functions are in with.js and their tests are in test_with.js.

I also sent a patch to MochiKit so if they accept it we Pythonistas can all have our little sense of being home (and actually MochiKit does a great job to make Python developers feel in the right place!).

bz2 module completed

I’ve finished porting the CPython’s bz2 module to ctypes plus PyPy and this was the last module in my SoC proposal :-)

It doesn’t compile yet, for the same reason _ssl doesn’t compile either. PyPy’s rctypes has some limitations in structures and function pointers.

In those days I realized how nice is bzip2 library and how simulating pointers in Python can be a pain…

New books

I just received my two new books from Amazon:

designing_with_web_standards_2nd_edition
python_in_a_nutshell_2nd_edition

PyAppleSMS

Michele Ferretti released PyAppleSMS, a tool to use the Sudden Motion Sensor shipped in the latest Apple’s notebooks. You can find it here: http://code.google.com/p/pyapplesms/

Code example:

  1. #!/usr/bin/env python
  2.  
  3. import applesms
  4. import time
  5.  
  6. try:
  7.     while True:
  8.         x, y, z = applesms.coords()
  9.         print x, y, z
  10.         time.sleep(1)
  11. except applesms.error, e:
  12.     print ‘an error occurred: %s’ % str(e)

Have fun!