Attack a sacred Python Cow

castironpi castironpi at gmail.com
Thu Jul 24 13:34:40 EDT 2008


On Jul 24, 11:49 am, "Sebastian \"lunar\" Wiesner"
<basti.wies... at gmx.net> wrote:
> Torsten Bronger <bron... at physik.rwth-aachen.de>:
>
>
>
> > Hallöchen!
>
> > Bruno Desthuilliers writes:
>
> >> Torsten Bronger a écrit :
>
> >>> Bruno Desthuilliers writes:
>
> >>>> [...]
>
> >>>> How would you handle this case with an implicit 'self' :
>
> >>>> class Foo(object):
> >>>>    pass
>
> >>>> def bar(self):
> >>>>    print self
>
> >>>> Foo.bar = bar
>
> >>> Just like this.  However, the compiler could add "self" to
> >>> non-decorated methods which are defined within "class".
>
> >> What's defined within classes are plain functions. It's actually
> >> the lookup mechanism that wraps them into methods (and manage to
> >> insert the current instance as first argument).
>
> > And why does this make the implicit insertion of "self" difficult?
> > I could easily write a preprocessor which does it after all.
>
> Who said, that it would be "difficult"?  He just corrected your statement
> about definitions inside a class, and did not make any assumption about
> making "self" implicit.
>
> I'd assume, that making self implicit wouldn't be that difficult to assume.
> But does the fact, that it could easily be done, alone mean, that it
> _should_ be done?  The explicit "self" was a design decision, that can't
> really be judged by technical arguments from implementation side.  Its a
> discussion about design from a programmers point of view ...
>
> --
> Freedom is always the freedom of dissenters.
>                                       (Rosa Luxemburg)

I don't think you can infer from 'explicit is better than implicit'
that 'the more explicit the better'.  For instance, we don't use:

python.callbyvalue.foo( bar, 1, 2 )
python.callbyref.foo2( bar, x, y )

or further:

foo( byref bar, byval 1, byval 2 )
foo2( byref bar, byref x, byref x )

though some languages do.

Python doesn't do that much implicity, like copying, with the
exception of copying strings, which some string functions do, such as
lower, replace, strip.  (Does slicing return a new string?)

What is the most surprisingly implicit behavior in Python?  What is
the most explicit?



More information about the Python-list mailing list