prototyping good OOdesign in Python?

Eric Brunel eric.brunel at
Thu Jun 6 12:32:10 CEST 2002

Geoff Gerrietts wrote:
> Since Python doesn't care about most of this stuff, modelling it is
> only useful if you expect to port the code later.

Eeeer, maybe I'll start yet another flame war here, but I strongly disagree 
with this statement! Modelling is *always* useful if your application isn't 
a "quick and dirty" one, is significantly large and/or if it may have 
several versions and/or several persons that will work on it. UML diagrams 
are not just another representation of the code: it allows the developers 
to take a step back and look at the whole picture instead of just their 
little part of the code. If you have several cooperating classes, it also 
allows to visually design these cooperations, instead of having to look 
everywhere in the code to see where a particular class is used (and also 
*if* it's still used at all...). In fact, I find UML design particularly 
useful on large/medium Python applications, precisely *because* of Python's 
dynamic features and lack of strong typing. If you want your code to be 
readable by other people than just yourself, and maybe at a time where 
you'll not even be around anymore, a good documentation of the code is 
really needed...

Whether UML is well-suited for documenting Python applications is of course 
debatable. I personaly find it quite convenient:

- on one hand, it counter-balances the "fuzzy" part of Python (no 
declarations, everything is dynamic) by allowing to actually declare 
everything. Let's be honest here: in a significantly large application, a 
big part of the code make assumptions on the objects it handles, and may 
benefit from strong typing. Not having to declare everything's type is 
quite handy, but may in the end make the code unreadable if you do not have 
something that tells you what is needed on the objects you manipulate...

- on the other hand, UML is quite open and may also allows to document 
"fuzzy" features, or things really specific to a language like Python. For 
example, UML doesn't know anything about Python dictionaries, since 
dictionaries are quite often not natively supported by other languages. But 
if you know your target language will be Python, you may just use a 
specific "custom" type like "dict<key type, value type>" in your UML spec. 
Of course, if the tool you use to design your UML diagrams is too 
restrictive, it may report an error on this kind of declaration, but 
well..., no big deal... The whole purpose of UML diagrams is documentation, 
not making correct diagrams for Rational Rose or whatever other tool...

Of course, many features of UML tools cannot be used at all with Python: 
semantics checking may be disturbed by your custom Python types, and I 
don't know a single UML tool that can generate Python code (if anybody 
knows one, please let me know!). But again: no big deal... When you'll get 
back to your code in a few months or years, you'll be really glad to have 
your UML spec at hand to understand how your few dozens classes speak to 
each other...
- Eric Brunel <eric.brunel at> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list