python without OO

John Hunter jdhunter at ace.bsd.uchicago.edu
Wed Jan 26 22:21:17 EST 2005


>>>>> "Davor" == Davor  <davorss at gmail.com> writes:

    Davor> not really - it was not my intention at all - but it seems
    Davor> people get upset whenever this OO stuff is mentioned - and
    Davor> what I did not expect at all at this forum as I believed
    Davor> Python people should not be so OO hardcore (seems not all
    Davor> as quite a few have indicated in their
    Davor> replies)... Nevertheless, I think the discussion has
    Davor> several quite good points!  --
    Davor> http://mail.python.org/mailman/listinfo/python-list

Consider the case of a list, say 

x = [1,2,3,4]

suppose you wanted to reverse the list, so that x becomes [4,3,2,1].
In a procedural language, one might do

  x = reverse(x)

In an OO language such as python, one might do

  x.reverse()

Is the OO way more obscure and complicated, etc?  Not really -- it's
only a minor syntactical difference.  One of the core ideas behind OO
programming is that data (the contents of the list 1,2,3,4) and
methods (sorting, reversing) are bound together into a single entity,
the object.  On the face of it, this is rather sensible.

You may rightly recoil against unnecessary abstraction and complexity,
abuse of multiple inheritance and so on.  That's perfectly sensible.
But object orientation is probably not the bogey man here.  python
values readable code that is as simple as possible (but no simpler!)
as you seem to.  Focus on the actual problem, which is probably not OO
programming, but colleagues who are making a design more complex than
need be.

Indeed, the third chant in the mantra of python is "Simple is better
than complex."

John-Hunters-Computer:~> python
Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!



More information about the Python-list mailing list