Re: Self in the Argument List: Redundant is not Explicit
Posted: Sep 25, 2008 2:24 PM
@Kay """The self parameter assigned to the keyword argument must exist once the class C is created"""---i’d believe the deeper trouble with the formulation you gave,
self = self in the method declaration, as you pointed out, is that there is a necessity to ‘beam’ a
self into position at the appropriate point in time. we already do exactly that:
mything right into the first position of the ensuing call,
f(mything). this is without doubt a much better choice than breaking expectations about at what point in time default values get assigned, as people find that point already a little hard to guess. so the very point where
self is landed---when it will be available to whom?---is well chosen, as it is easy to mentally trace and understand.
i tried to get friends with any of the proposed solutions, but none can convince me. right here and now, my feeling is that we should make
self less of a hard rule and lift it a bit into keyword space (but not quite), by simply stopping to insist on
self having to appear in the signature.
i suggest: to make the appearance of a first parameter
self in object method declarations an option. thus, code as already exists can go on, code that is to be written will see that all lines
def f(x,y): will be read exactly as
that is, in our incantation, we just leave out a word that we know is always there, be it explicit or implicit. this could happen at a fairly early stage in parsing. the resulting (modified) method object irons over the deficient signature, but also keeps the information that something particular happened within the vm tree.
this step would satisfy all code that does not use something but
self for the intended purpose---people who put a
self later in the signature can receive warnings, and people who use another name for
self (i heard some people use
s) can expect their code to break in mysterious ways, which suits them well ;-)