Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Another Language Change for Debate
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Chermside  
View profile  
 More options Jan 11 2002, 2:04 pm
Newsgroups: comp.lang.python
From: Michael Chermside <mch...@destiny.com>
Date: Fri, 11 Jan 2002 13:21:34 -0500
Local: Fri, Jan 11 2002 1:21 pm
Subject: Another Language Change for Debate
Okay, for some reason this newsgroup tends to get WAY more suggestions
for language changes than that for any other language that I know. I
suppose that there are a couple of reasons for this. One is cultural,
another is that Python definitely IS being improved and extended
(witness brilliant advances like iterators, generators, and the
beginnings of a fix for the type-class chasm). My conceit is that
another reason is that Python is so VERY nice already that it's the
language to which most people want to add their own pet idea. But I
suspect that the NUMBER ONE reason is that the people who read and write
on c.l.p are, on the whole, VERY GOOD at language design.

So I'll throw out an idea of my own for discussion. This is NOT a PEP...
and therefore NOT a serious proposal for a change in Python. I just want
to hear what other people think about it and compare your sense of
language design with my own.

One of the things that still throws me in Python is writing things like
this:

class MyClass(OtherClass):
    def addItems( newItems ):
       self.items += newItems

Of course what I've forgotten to do here is to declare 'self' as the
first parameter to addItems(). The reason I forgot is that when I CALL
the method it looks like this:
      myObj.addItems( userItems )
so when I'm writing it I'm thinking of it as a function of one parameter.

Proposals for leaving off 'self' have been made many times, but that's a
bad idea... the fact that every variable reference is (1) local, (2)
nested scoped, or (3) global and can be found by a simple textual search
through the source code is a VERY ELEGANT thing about Python. But
writing the method one place with 2 arguments and another place with
just 1 is not elegant.

So here's my idea. Allow the following syntax:

class MyClass(OtherClass):
    def self.addItems( newItems ):
       self.items += newItems

So in method declarations where we normally permit only an identifier
for the method-name, we now allow also identifier '.' identifier. The
identifier before the dot simply becomes the first parameter of the
method. I don't think it would be good style to use this for non-methods
(ie, normal functions not belonging to a class), but I suppose there's
no reason to prohibit the syntax. There's no way to set default values
for this parameter, but you don't do that with 'self' anyhow, right?

As far as I can tell, there'd be no syntactic ambiguity (please correct
me if I've missed something). And it would make the DECLARATION of a
method look a whole lot more like the USE of the method, without
removing the elegance of declaring 'self' like any other variable.

So... what do you folks think?

-- Michael Chermside


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.