Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22036 > unrolled thread
| Started by | "J. Cliff Dyer" <jcd@sdf.lonestar.org> |
|---|---|
| First post | 2012-03-22 14:12 -0400 |
| Last post | 2012-03-22 14:12 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python classes: Simplify? "J. Cliff Dyer" <jcd@sdf.lonestar.org> - 2012-03-22 14:12 -0400
| From | "J. Cliff Dyer" <jcd@sdf.lonestar.org> |
|---|---|
| Date | 2012-03-22 14:12 -0400 |
| Subject | Re: Python classes: Simplify? |
| Message-ID | <mailman.895.1332439968.3037.python-list@python.org> |
The issue of explicitly naming a "self" parameter has been discussed in
depth on a number of occasions. I recommend a google search for "python
implicit self" for some of the reasons why it exists. Here's what Guido
has to say about it:
http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html
Cheers,
Cliff
On Thu, 2012-03-22 at 13:15 +0000, Andrea Crotti wrote:
> On 03/22/2012 10:51 AM, Steven Lehar wrote:
> > It seems to me that the Python class system is needlessly confusing.
> > Am I missing something?
> >
> >
> > For example in the class Complex given in the documentation
> >
> >
> > class Complex:
> > def __init__(self, realpart, imagpart):
> > self.r = realpart
> > self.i = imagpart
> >
> >
> > x = Complex(3.0, -4.5)
> >
> >
> > I initially found it profoundly confusing that __init__( ) calls for
> > 3 arguments, but you call Complex( ) with 2. Furthermore, why not
> > call the initialization function after the class name as is done in
> > other languages? Isn't that the simplest conceptually? Demonstrating
> > with the above example:
> >
> >
> > class Complex:
> > def Complex(realpart, imagpart):
> > Complex.r = realpart
> > Complex.i = imagpart
> >
> >
> > x = Complex(3.0, -4.5)
> >
> >
> > Is there a good reason why classes cannot be defined that way?
> > (Besides the problem of backward-compatibility)
> >
> >
>
> Some time ago I saw some nasty hack that allowed you to drop the self
> in the method declaration,
> using some crazy metaclass trick, but that's really not a good idea ;)
>
> I agree that is counter-intuitive but just set your editor to do that
> for you and you will be fine..
>
> in my emacs
> - s TAB -> self
> - . TAB -> self.
> - m TAB -> def ${1:method}(self$2):
> $0
>
> so I never actually write the self..
Back to top | Article view | comp.lang.python
csiph-web