SV: Python Productivity over C++

Martijn Faassen m.faassen at vet.uu.nl
Wed Jun 14 07:41:48 EDT 2000


Thomas Thiele <thiele at muc.das-werk.de> wrote:

> How should a REAL python program looks like.
> I design classes like in C++, thats true. But I also use typical python features
> like lists, dicts, map etc. I'm not trying to write everything by myself.

> How have I to think as a pythonprogrammer?

There are differences in approach and philosophy between Python and C++ (or 
Java or one of the other statically typed languages):

Some of my observations on Python 'style':

  * Pythoneers care less about encapsulation. That is, they like 
    encapsulation but they don't go out of their way doing getters/setters
    and the like; the idea is to encapsulate later, when it becomes
    necessary. Python allows this as prototyping can go really quickly.
    The dynamic typing aspect also allows a lot of easy loose-coupling 
    straight away.

  * Pythoneers care less about inheritance hierarchies. When a class
    supports an interface it supports an interface; inheritance often
    isn't needed. 

  * Pythoneers care less about static type safety (obviously). They don't worry
    a lot inside any method or function what type the passed
    arguments are (they may sometimes query if it supports an interface,
    though). They'll worry about that when passing the arguments
    in.

  * Pythoneers care more about interfaces, but worry less about them.
    Lots of interfaces are implicit, but that's fine, as Python's
    dynamicity allows them to make the code do the right thing 
    anyway. Interfaces aren't really types, so there's less worry
    about breaking interfaces.

  * Pythoneers care more about rapid prototyping. The language allows it,
    so they often write one to throw it away. Or at least overhaul it
    drastically. Or not, as it may turn out.

  * Pythoneers care more about (unit) tests. Again, tests are easier and quicker
    to write because the language allows rapid prototyping.

  * Pythoneers worry less about reuse. While reuse with Python is very
    easy to accomplish, they don't have to *worry* about it; it just
    happens when it does. When it doesn't, it's because it's too easy
    to whip something up quickly yourself.

  * Pythoneers use Python's introspection abilities such as hasattr() and
    isinstance(). Not all the time, not even frequently, but often enough
    it's very convenient glue to make things work the way they want, 
    without having to complicate (or even touch) everything else. Use it
    when the design would've painted you in a corner in a statically
    typed language.

Of course, any of these may be wrong. :)

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list