[TriLUG] OOP book recommendations

Tom Bryan tbryan at python.net
Wed Jul 24 18:06:44 EDT 2002


On Wednesday 24 July 2002 01:42 pm, Paul D. Boyle wrote:

> I had heard that Python's OO capabilities  were tacked on after the
> initial design and implementation.

I'm too lazy to go read the history, but I don't think so.  I believe the OO 
was there from the beginning.  From using Python, it sure feels that way.  
(As opposed to the way that OO really *felt* grafted on to Perl the moment I  
touched OO programming in Perl.)  

You're probably referring to the "type class split" in Python.  If you know 
Java, you know that primitives aren't objects.  Thus, the difference between 
int and Integer.  Python had a similar sort of problem with its built-in 
types.  Python's types weren't really part of the class system, making it 
difficult to do things like subclass string.  I believe the type class split 
is healed in Python 2.2.  

For example, 
$ python
Python 2.2.1 (#1, Jun 15 2002, 17:05:40)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo( str ):
...     pass
...
>>> x = Foo()
>>> x
''>>> dir(x)
['__add__', '__class__', '__contains__', '__delattr__', '__dict__', '__doc__', 
'__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', 
'__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', 
'__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__repr__', 
'__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 
'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 
'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 
'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 
'translate', 'upper']

Whereas, with previous versions, that would have given
$ python2.1
Python 2.1.3 (#1, Jun 15 2002, 16:44:47)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> class Foo( str ):
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: base is not a class object

> I am also playing around with the idea of learning an interpreted OO
> language.  I feel some interest in learning Ruby, but Python seems more
> widely used.  If there are people on this list who code in both (or either)
> Ruby or Python, I would be interested in hearing your opinions.

I like Python a lot.  I've heard a lot of good things about Ruby, but I 
haven't bought my first Ruby book yet.  I can tell you that one thing Python 
was known for in the past was its very friendly users.  Deliberate flames 
along the lines of "Python is stupid because X" on comp.lang.python were 
often turned into useful threads discussing Python's merits and warts and how 
to address community proposals for changes (eventually resulting in the 
current system of Python Enhancement Proposals (PEPs)).

And FWIW, I'm almost ready to announce the (attempt to form) an informal 
Triangle-area Zope/Python User Group.

---Tom




More information about the TriLUG mailing list