473,412 Members | 4,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

explicit self revisited

The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version):

1. Instance variables can be easily distinguished from local variables.

2. A method from a particular class can be called as
baseclass.methodname(self, <argument list>).

3. No need for declarations to disambiguate assignments to local/instance
variables.

All these reasons are valid and retained by the following suggestion: let
self be represented by the dot, e.g. replace

class someTest(unittest.TestCase):
def setUp(self):
self.ly = yList()
self.m1 = self.ly[0].message
self.m2 = self.ly[1].message
self.m3 = self.ly[2].message

def testList(self):
self.assertEqual(len(self.ly),3)
self.assertEqual(self.m1),"Ho")
self.assertEqual(self.m2),"HoHo")
self.assertEqual(self.m3),"HoHoHo")

by

class x(unittest.TestCase):
def .setUp():
.ly = yList()
.m1 = .ly[0].message
.m2 = .ly[1].message
.m3 = .ly[2].message

def .testList():
.assertEqual(len(.ly),3)
.assertEqual(.m1),"Ho")
.assertEqual(.m2),"HoHo")
.assertEqual(.m3),"HoHoHo")

Methods could still be referenced e.g. as x.testList(someInstance).
The current self syntax could still be valid (for backward compatibility.)
Advantages of the new syntax:

1. Enhanced readability, less verbosity

2. Unambiguous: no need to tell newbies that a virtuous pythoneer
has to stick to self instead of abbreviate it as s.

3. One argument less for "Python OO bolted on" propaganda.

The second reason is the most important for me. I consider syntax control
by a code of conduct as lame.

The "leading dot" syntax could have further advantages:

class x(object):
a = "" # static variable
.b = 0 # instance variable

This could replace parameterless __init__ methods. Methods without leading
dots could be considered static without a staticmethod decorator. For
backward compatibility this behaviour should be explicitly activated e.g. by
__autostatic__ = true.

What do you think?

--
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
Nov 11 '06 #1
24 2256
Peter Maas wrote:
What do you think?
cannot all you clueless trolls who cannot think of a single useful thing
to contribute to Python start your own newsgroup?

</F>

Nov 11 '06 #2
cannot all you clueless trolls who cannot think of a single useful thing
to contribute to Python start your own newsgroup?
and before anyone complains; please note that they're working through

http://www.effbot.org/pyfaq/design-index.htm

one article at a time. who's going to be the first one to argue that
Python needs a goto statement ?

</F>

Nov 11 '06 #3

Fredrik Lundh wrote:
Fredrik Lundh wrote:
cannot all you clueless trolls who cannot think of a single useful thing
to contribute to Python start your own newsgroup?

and before anyone complains; please note that they're working through

http://www.effbot.org/pyfaq/design-index.htm
That site is a bunch of FUD -
The explicit self is there simply because OOP was tacked onto python as
an afterthought.
Why not just be honest about it. It's too late to change Python's
syntax. It just means a little extra typing. If it really bothers
someone, use "s" instead of "self" or else use Ruby.

Nov 11 '06 #4
Doug (Holton?) wrote:
>and before anyone complains; please note that they're working through

http://www.effbot.org/pyfaq/design-index.htm

That site is a bunch of FUD -
the official FAQ is a bunch of FUD? are you sure you know what FUD means?

</F>

Nov 11 '06 #5

DougThe explicit self is there simply because OOP was tacked onto
Dougpython as an afterthought.

Got a reference to support that claim?

Skip
Nov 11 '06 #6
On Sat, 11 Nov 2006 18:09:59 -0600, skip wrote:
>
DougThe explicit self is there simply because OOP was tacked onto
Dougpython as an afterthought.

Got a reference to support that claim?
Of course not, since it is a classic example of trolling.

By comparison, the way I read the Original Poster, he was sincere if
misguided -- but Doug's bullshit response is a typical attempt to throw
petrol on an already hot situation.
--
Steven.

Nov 12 '06 #7
Dennis Lee Bieber wrote:
>one article at a time. who's going to be the first one to argue that
Python needs a goto statement ?
Especially since there is a comefrom <G>
ah, good point. I've updated the FAQ.

</F>

Nov 12 '06 #8
On Sat, 11 Nov 2006 22:39:37 +0100, Peter Maas wrote:

[snip]
let self be represented by the dot, e.g. replace

class someTest(unittest.TestCase):
def setUp(self):
self.ly = yList()
self.m1 = self.ly[0].message
self.m2 = self.ly[1].message
self.m3 = self.ly[2].message
by

class x(unittest.TestCase):
def .setUp():
.ly = yList()
.m1 = .ly[0].message
.m2 = .ly[1].message
.m3 = .ly[2].message
On the assumption that Peter was sincere, and not trolling, I thought I'd
make a point-by-point response, but then X crashed and took my post with
it. So here's the brief version.

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?

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

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.)

Even more fundamentally, any time you need to pass the instance to a
function, you need an explicit self. (Delegation is a special case of this.)

def __str__(self):
# I like semicolons and dislike square brackets.
return ';'.join(self)

--
Steven.

Nov 12 '06 #9

Fredrik Lundh wrote:
Doug wrote:
>>
Fredrik Lundh wrote:
>>Fredrik Lundh wrote:
cannot all you clueless trolls who cannot think of a single useful thing
to contribute to Python start your own newsgroup?
>>and before anyone complains; please note that they're working through
>> http://www.effbot.org/pyfaq/design-index.htm

That site is a bunch of FUD -
The explicit self is there simply because OOP was tacked onto python as
an afterthought.
Why not just be honest about it. It's too late to change Python's
syntax. It just means a little extra typing. If it really bothers
someone, use "s" instead of "self" or else use Ruby.

the official FAQ is a bunch of FUD? are you sure you know what FUD means?

</F>
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?
And yes, actually, the dash after FUD was where I was going to link to
a definition of FUD to show I really meant to use that term. It
doesn't appear that you believe anything that isn't on your own effbot
site, however.

Nov 12 '06 #10
Dennis Lee Bieber <wl*****@ix.netcom.comwrote:
On Sun, 12 Nov 2006 01:55:35 +0100, Fredrik Lundh
<fr*****@pythonware.comdeclaimed the following in comp.lang.python:

>>
ah, good point. I've updated the FAQ.
Ah, but do we dare update the Wikipedia link to include Python as a
language capable of COMEFROM? <G>
Somebody definitely should. The current wikipedia article contains an
example in a hypothetical dialect of BASIC ('because an actual example in
INTERCAL would be too difficult to read'). Somebody should enhance the
article with the equivalent example in Python which is both easy to read
and can actually be run:

from goto import goto, comefrom, label

comefrom .repeat
name = raw_input('what is your name? ')
if name:
print "Hello",name
label .repeat

print "Goodbye!"

Nov 12 '06 #11
On Sun, 12 Nov 2006 02:14:32 -0500, Doug <aj******@gmail.comwrote:
I was going to link to
a definition of FUD to show I really meant to use that term.
Oooh.
If you had just mentioned your dyslogia,
it would have saved us all some time.
Thanks!
Alan
Nov 12 '06 #12
On Sat, 2006-11-11 at 23:14 -0800, Doug wrote:
Fredrik Lundh wrote:
Doug wrote:
>
Fredrik Lundh wrote:
Fredrik Lundh wrote:
cannot all you clueless trolls who cannot think of a single useful thing
to contribute to Python start your own newsgroup?

and before anyone complains; please note that they're working through

http://www.effbot.org/pyfaq/design-index.htm

That site is a bunch of FUD -
The explicit self is there simply because OOP was tacked onto python as
an afterthought.
Why not just be honest about it. It's too late to change Python's
syntax. It just means a little extra typing. If it really bothers
someone, use "s" instead of "self" or else use Ruby.
the official FAQ is a bunch of FUD? are you sure you know what FUD means?

</F>

You idiot. Putting the word "official" in front of something doesn't
mean it can't be FUD.
Fredrik doesn't have to prove that the official FAQ isn't FUD. You,
Doug, have to prove that it is, because you accused it of being FUD.

By your logic, I can prove that you are a piece of cheddar cheese. I
will simply assert that you are a piece of cheddar cheese. You might
respond by making a surprisingly lucid (for a piece of cheddar) argument
that you are a sentient being. To this I will respond "You idiot,
proving that you are a sentient being doesn't mean you can't be a piece
of cheddar." QED.

Since you are too lazy to post the wikipedia link, please allow me:
http://en.wikipedia.org/wiki/Fear%2C...inty_and_doubt

According to that definition, FUD is "a sales or marketing strategy of
disseminating negative (and vague) information on a competitor's
product."

Even if the FAQ could, by a stretch of the imagination, be considered a
sales or marketing strategy, you'd be hard-pressed to find evidence of
it disseminating negative information on a competitor's product. Hence,
it's not FUD.

-Carsten
Nov 12 '06 #13
Carsten Haese wrote:
According to that definition, FUD is "a sales or marketing strategy of
disseminating negative (and vague) information on a competitor's
product."
Doug "cheddar cheese" Holton (who has a long history of posting
seriously confused and/or abusive stuff under a number of aliases) is
a developer of a "competing" language named Boo.

I suppose that in his view, language advocacy is a zero-sum game, so
positive comments about Python can be considered as FUD against his own
project. He's even invented his own del.icio.us tag for this purpose:

http://del.icio.us/tag/pythonfud

</F>

Nov 12 '06 #14
I suppose that in his view, language advocacy is a zero-sum game, so
positive comments about Python can be considered as FUD against his own
project. He's even invented his own del.icio.us tag for this purpose:

http://del.icio.us/tag/pythonfud
now at:

http://del.icio.us/tag/python-fud

</F>

Nov 12 '06 #15
Peter Maas wrote:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version):

1. Instance variables can be easily distinguished from local variables.

2. A method from a particular class can be called as
baseclass.methodname(self, <argument list>).

3. No need for declarations to disambiguate assignments to local/instance
variables.

All these reasons are valid and retained by the following suggestion: let
self be represented by the dot <snip>
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 (see Steven
d'Aprano's post) and also I like the fact that I can spell it 'cls' in
classmethods and in
metaclasses. After a while one gets used to it and if you think a bit
it makes quite a
lot sense. Also, having the self explicit, makes Python object system
better (i.e.
it goes more in the direction of CLOS and less in the direction of
Java).

Michele Simionato

Nov 13 '06 #16
Doug wrote:
[...]
The explicit self is there simply because OOP was tacked onto python as
an afterthought.
No, it was added in such a way that Python would be useful as a
procedural as well as an OO language.

I don't know what's got into me.

can't-normally-say-boo-to-a-goose-ly y'rs - steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Nov 13 '06 #17
"Dennis Lee Bieber" <wl*****@ix.netcom.comwrote:

Especially since there is a comefrom <G>

*breaks into song* : "Oh Susannah, now don't you cry for me..."

Nov 13 '06 #18
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!

Nov 13 '06 #19
On 11/13/06, Fredrik Lundh <fr*****@pythonware.comwrote:
>
I suppose that in his view, language advocacy is a zero-sum game, so
positive comments about Python can be considered as FUD against his own
project. He's even invented his own del.icio.us tag for this purpose:

http://del.icio.us/tag/pythonfud

now at:

http://del.icio.us/tag/python-fud

</F>
Hey, Fredrik, you have your own tag!
<http://del.icio.us/tag/fredrik-lundh-trollI wish *I* had my own
tag. ;-)

I notice that, as you predicted, Python's lack of a goto is in there too.

--
Cheers,
Simon B
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
Nov 13 '06 #20
Simon Brunning a écrit :
On 11/13/06, Fredrik Lundh <fr*****@pythonware.comwrote:
>>
I suppose that in his view, language advocacy is a zero-sum game, so
positive comments about Python can be considered as FUD against his own
project. He's even invented his own del.icio.us tag for this purpose:

http://del.icio.us/tag/pythonfud

now at:

http://del.icio.us/tag/python-fud

</F>

Hey, Fredrik, you have your own tag!
<http://del.icio.us/tag/fredrik-lundh-trollI wish *I* had my own
tag. ;-)

I notice that, as you predicted, Python's lack of a goto is in there too.
Hey, this is fun :D I also found that one :
http://del.icio.us/dholton/python-fud-by-fredrik-lundh

But is seems they all point to the same article than yours so you get
the points for it ;)
Nov 13 '06 #21
Michele Simionato wrote:
Peter Maas wrote:
>All these reasons are valid and retained by the following suggestion: let
self be represented by the dot <snip>

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 ;)

--
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
Nov 13 '06 #22
Peter Maas wrote:
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>

Nov 13 '06 #23
Steven D'Aprano schrieb:
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.

--
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
Nov 13 '06 #24
Peter Maas wrote:
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
Nov 18 '06 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Dick | last post by:
Derived classes sometimes need to delegate portions of the work in overridden methods to methods in their base classes. This was traditionally done with explicit calls in python, e.g., class...
1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
5
by: sandman | last post by:
I've been testing my web app on another workstation to simulate using the server time. The test pc's time is an hour behind the server time and when the user processes a request, the server time...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
6
by: ian | last post by:
Hi All I have a DLL (nahd.dll) that has been supplied to me will a PBX phone system. According to the documentation it is to allow developers to write there own applications to monitor the...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
26
by: samjnaa | last post by:
Hello. Please tell me whether this feature request is sane (and not done before) for python so it can be posted to the python-dev mailing list. I should say first that I am not a professional...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.