How to write Smart Python programs?

John Salerno johnjsal at
Wed Oct 11 16:28:31 CEST 2006

Bruno Desthuilliers wrote:

> Googling for "python is not java" may be a good start.

I have a question about this section of a blog with that title. I'll ask 
the question first so it doesn't get lost at the bottom: does the 
following opinion of XML apply to GUIs? (i.e., using an XML resource to 
define a GUI layout rather than coding it yourself).



XML is not the answer. It is not even the question. To paraphrase Jamie 
Zawinski on regular expressions, "Some people, when confronted with a 
problem, think "I know, I'll use XML." Now they have two problems."

This is a different situation than in Java, because compared to Java 
code, XML is agile and flexible. Compared to Python code, XML is a boat 
anchor, a ball and chain. In Python, XML is something you use for 
interoperability, not your core functionality, because you simply don't 
need it for that. In Java, XML can be your savior because it lets you 
implement domain-specific languages and increase the flexibility of your 
application "without coding". In Java, avoiding coding is an advantage 
because coding means recompiling. But in Python, more often than not, 
code is easier to write than XML. And Python can process code much, much 
faster than your code can process XML. (Not only that, but you have to 
write the XML processing code, whereas Python itself is already written 
for you.)

If you are a Java programmer, do not trust your instincts regarding 
whether you should use XML as part of your core application in Python. 
If you're not implementing an existing XML standard for interoperability 
reasons, creating some kind of import/export format, or creating some 
kind of XML editor or processing tool, then Just Don't Do It. At all. 
Ever. Not even just this once. Don't even think about it. Drop that 
schema and put your hands in the air, now! If your application or 
platform will be used by Python developers, they will only thank you for 
not adding the burden of using XML to their workload.

(The only exception to this is if your target audience really really 
needs XML for some strange reason. Like, they refuse to learn Python and 
will only pay you if you use XML, or if you plan to give them a nice GUI 
for editing the XML, and the GUI in question is something that somebody 
else wrote for editing XML and you get to use it for free. There are 
also other, very rare, architectural reasons to need XML. Trust me, they 
don't apply to your app. If in doubt, explain your use case for XML to 
an experienced Python developer. Or, if you have a thick skin and don't 
mind being laughed at, try explaining to a Lisp programmer why your 
application needs XML!)

More information about the Python-list mailing list