Does Python really follow its philosophy of "Readability counts"?

BJörn Lindqvist bjourne at gmail.com
Sun Jan 11 22:59:34 CET 2009


2009/1/11 Madhusudan.C.S <madhusudancs at gmail.com>:
> Django's code for some reason. I have now strongly started feeling if
> Python really follows its
> "Readability Counts" philosophy. For example,
>
>    class A:
>    a = 10
>    b = "Madhu"
>
>    def somemethod(self, arg1):
>        self.c = 20.22
>        d = "some local variable"
>        # do something
>        ....
>    ...
>    def somemethod2 (self, arg2):
>        self.c = "Changed the variable"
>        # do something 2
>        ...

In this case is the "c" attribute not "declared" in the __init__() method of A?

> I am interested in knowing if I am reading this kind of code in the
> wrong way mostly because
> of C++/Java hangover since most other languages follow the same
> approach as them? If there
> is a Pythonic way reading this code for better readability? What made
> Python developers to
> adopt this strange strategy keeping "Readibility Counts" in mind?

Not declaring instance variables is just poor form. IMHO Python code
should mostly be written like C++/Java. When you use "tricks" like the
above (dynamically adding attributes to a class) or getattr calls,
catching AttributeErrors, manipulating __dict__, decorators or
metaclasses you should really think twice whether you actually _need_
to use those tricks.


-- 
mvh Björn



More information about the Python-list mailing list