Attack a sacred Python Cow

Marcus.CM marcus at internetnowasp.net
Sun Jul 27 04:23:06 CEST 2008


Well after reading some of these posts on "sacred python cow" on the 
"self" , i would generally feel that most programmers
who started with C++/Java would find it odd. And its true, i agree 
completely there should not be a need to put "self" into every single
member function. If you were writing an application and one of your 
classes adds the same variable to each of its member function you would 
do away with it too.
What could be done instead is :-

1. python should hardcode the keyword "self". So whenever this keyword 
is used, it would automatically implied that it is
referring to a class scope variable. This would be similar to how the 
"this" keyword is used in C++.

2. Omit self from the parameter.

class Abc :
      def  DoSomething (a,b,c) :
            # class variable
            self.somevar = a
            self.someblar = b
            self.somec = c
            somevar = a * b  # local variable
         




Russ P. wrote:
> On Jul 26, 2:25 pm, Terry Reedy
>   
>> There is a lot of code you have not seen.  Really.  In informal code I
>> use 's' and 'o' for 'self' and 'other'.  I don't usually post such
>> because it is not considered polite.  So you have seen a biased sample
>> of the universe.
>>     
>
> You take the name down to a single letter. As I suggested in an
> earlier post on this thread, why not take it down to zero letters? You
> could if Python accepted something like
>
> class Whatever:
>
>     def fun( , cat):
>
>         .cat = cat
>
> This is even better than the single-character name, not only because
> it is shorter, but also because there is no question that you are
> referring to "self." No need to look back at the method signature to
> verify that.
>
> For those who don't like the way the empty first argument looks, maybe
> something like this could be allowed:
>
>     def fun( ., cat):
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   





More information about the Python-list mailing list