explicit self revisited

F

fynali

You idiot. Putting the word "official" in front of something doesn't
mean it can't be FUD. Especially when it is written by people such as
yourself. Have you not paid attention to anything happening in
politics around the world during your lifetime?

Ridiculous boo-llshit!
 
P

Peter Maas

Michele said:
This suggestion has been discussed in the past (I remember having the
same idea myself when I first learned Python). But at the end I believe
the explicit 'self' is a better solution, because there are cases where
it is useful to have it

Thanks, Michele. My intention wasn't to abandon explicit self but to replace
it by a shorter and unique entity. I searched a little for similar suggestions
in the past but didn't find them so I decided to post. I admit that my
suggestion was half-baked.

But at least I learned something: a heated debate isn't bound to become an
endless thread if the OP abstains from answering idiot replies ;)
 
F

Fredrik Lundh

Peter said:
But at least I learned something: a heated debate isn't bound to become an
endless thread if the OP abstains from answering idiot replies ;)

trolling is trolling even if you use smilies. I'm sure you can find a
way to actually *contribute* to Python if you really want to...

</F>
 
P

Peter Maas

Steven said:
Implicit self will never be used for Python, because it is redundant so
long as there is a need for explicit self, and there is a need for
explicit self because there are a number of basic, dare I say
*fundamental* programming techniques that require an explicit self.

For example, delegation.

class MyClass(Parent):
def method(self, arg):
Parent.method(self, arg)
# what are you going to write? Parent.method(,arg) maybe?

The idea is: let self (or self.) be represented by the dot alone,
therefore:

Parent.method(., arg) # :)
Here's another fundamental technique that implicit self breaks.

class MyList(list):
def __iadd__(self, other):
# in-place addition
other = transform(other) # do something to the argument
super(MyList, self).__iadd__(other) # call the superclass
# could be written .__class__.__iadd__(other)
# BUT be aware the semantics are NOT the same!
return self # and return the suitably modified instance

return .
You can't explicitly return the instance unless you have an explicit name
for it. (And if you are thinking of creating more magic syntax that
implicitly returns self, just don't bother.)

No magic. Just a dot. But perhaps a dot is too tiny. We could take JUST_ME
or ME_AND_BOBBY_MCGEE instead, of course as a reserved keyword followed by a
dot ;)

Thanks for your hints, Steven.
 
B

baalbek

Peter said:
No magic. Just a dot. But perhaps a dot is too tiny. We could take JUST_ME
or ME_AND_BOBBY_MCGEE instead, of course as a reserved keyword followed
by a
dot ;)

Why a dot, and not a @, like in Ruby and Perl?

I think a dot is a particular bad idea, not the least due to poorer
readability of code (and thou shall not underestimate the readability of
code!).

Baalbek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top