473,727 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.metho dname(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(unitte st.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.assertEqua l(len(self.ly), 3)
self.assertEqua l(self.m1),"Ho" )
self.assertEqua l(self.m2),"HoH o")
self.assertEqua l(self.m3),"HoH oHo")

by

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

def .testList():
.assertEqual(le n(.ly),3)
.assertEqual(.m 1),"Ho")
.assertEqual(.m 2),"HoHo")
.assertEqual(.m 3),"HoHoHo")

Methods could still be referenced e.g. as x.testList(some Instance).
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 'cGV0ZXIubWFhc0 B1dGlsb2cuZGU=\ n'.decode('base 64')
Nov 11 '06 #1
24 2296
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(unitte st.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.Test Case):
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(s elf, 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__.__ia dd__(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

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

Similar topics

1
1357
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 Derived(Left, Right): def __init__(self, myarg, larg, rarg): Left.__init__(self, larg) Right.__init__(self, rarg) self.data = myarg print 'derived'
1
5651
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 at the bottom. Hope you can help me understand the "explicit" keyword and its usage. Specifically, Is "explicit" keyword only associated with constructor in C++? What's "implied conversion of types"?
5
2457
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 is picked up. The problem is that I've got a "clock" on the web page that updates the "current time" every second since the app is time critical. The clock is a jscript routine. It seems to be picking up the local time. I'm just instantiating a...
2
6867
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 static explicit System.IntPtr (long);
6
4135
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 system. Now when I try to register this DLL I get an error. “DLL RegisterServer entry point not found” According to Microsoft this means it is not a DLL. I can view it using Dependency Walker and it has all the events mentioned in the...
31
3608
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(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
1
2320
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. X<Zx(y) is fine. Tested with gcc 2.95, 3.3, 4.1, all gave the same error: t.cpp: In function 'int main()': t.cpp:44: error: no matching function for call to 'D<int>::D(D<int>&)'
26
2544
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 programmer with too much technical knowledge. I would like to have something like the "option explicit" statement in Visual Basic which turns on C-like checking for declaration of variables. This is highly helpful for people who are coming from C/C+...
12
7204
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? class Trial { public: Trial() {
0
9406
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8103
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6703
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4786
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.