Python and Schools

Alex Martelli aleax at aleax.it
Sat Apr 12 12:58:23 EDT 2003


Mads Orbesen Troest wrote:

> On Fri, 11 Apr 2003 10:48:49 +0200, Harald Massa wrote:
> 
>> Yes, I love Python, and it is the most elegant programming language I
>> ever met.
> 
> I agree it's mostly elegant, but the OO features are clumsy in my oppinion
> (coming as a professional developer from other languages). Not as bad as

Interesting, because I also came to Python as a professional developer
from other languages (C++ above all) and the utter *ELEGANCE* of Python's
OO features was one of the things that hooked me to it irretrievably.

> Perl's bless-a-dictionary-into-being-a-class retro-fitting hack, of
> course, but really; all the self me here and self me there is - to me at
> last - exceedingly clumsy and a constant source of frustration.

Let's put it this way: in C++ you have to use this->foo SOME of the
time (to avoid running afoul of extremely subtle and deuced bugs
in some templates) but it's quite hard to predict exactly when you'll
need to do it.  With Python, you ALWAYS use self.foo (one character
less than C++'s this->foo!-) and thus your code is more regular and
uniform, there is no risk of ugly conventions such as naming member
variables m_this and m_that (popular in several C++ shops), no bugs
due to accidental local "hiding" of a member variable by a local one
(I've taught and consulted on C++ long enough to have seen THAT
happen many, MANY times -- and not to idiots, either... rather, to
very good professional programmers!) -- a HUGE amount of conceptual
AND pragmatical simplification of your life.

If that's the worst aspect of Python, then how must the rest be?-)

You can gain most (not quite all) of these advantages in C++ by 
using the this->foo way of accessing instance variables -- this 
also makes your C++ and Python code more similar, and helps you get
into the good habit.  And if any C++ bigot ever challenges you,
explain that this ensures optimal behavior of your code should it
ever be turned a template under ANY circumstances (it's true...!-).


Alex





More information about the Python-list mailing list