Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22036
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jcd@sdf.lonestar.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'guido': 0.03; 'parameter': 0.05; 'subject:Python': 0.05; 'nasty': 0.07; 'tab': 0.07; 'python': 0.08; 'arguments,': 0.09; 'am,': 0.12; 'def': 0.13; '"python': 0.15; '(besides': 0.16; 'cliff': 0.16; 'confusing.': 0.16; 'declaration,': 0.16; 'metaclass': 0.16; 'naming': 0.16; 'simplest': 0.16; 'subject:classes': 0.16; 'x-mailer:evolution 2.32.3': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'exists.': 0.18; 'seems': 0.20; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'implicit': 0.23; 'way?': 0.23; 'defined': 0.24; 'classes': 0.26; 'function': 0.27; 'cc:addr:gmail.com': 0.28; 'explicitly': 0.29; 'class': 0.29; 'example': 0.29; 'problem': 0.29; 'skip:b 20': 0.29; 'cc:addr:python.org': 0.29; 'depth': 0.30; 'url:2008': 0.30; 'ago': 0.31; 'subject:?': 0.31; 'actually': 0.31; 'thu,': 0.32; 'idea': 0.32; "isn't": 0.33; 'there': 0.33; 'agree': 0.33; 'discussed': 0.34; 'steven': 0.34; 'done': 0.34; 'crazy': 0.34; 'google': 0.35; 'cc:2**1': 0.36; 'received:org': 0.36; 'issue': 0.37; 'reasons': 0.37; 'but': 0.37; 'using': 0.37; 'skip:_ 10': 0.38; 'received:192': 0.38; 'some': 0.38; 'initially': 0.39; 'cannot': 0.39; 'missing': 0.40; 'url:blogspot': 0.61; 'your': 0.61; 'saw': 0.66; 'url:10': 0.72; '10:51': 0.84; '13:15': 0.84; 'andrea': 0.84; 'self.': 0.84; 'trick,': 0.84 |
| Subject | Re: Python classes: Simplify? |
| From | "J. Cliff Dyer" <jcd@sdf.lonestar.org> |
| To | Andrea Crotti <andrea.crotti.0@gmail.com> |
| In-Reply-To | <4F6B25D7.9020002@gmail.com> |
| References | <CAKz-UDNFpHF=2secHaFJ2M7LKAD4XtLLrqmE3uo1A6YVXH1zTg@mail.gmail.com> <4F6B25D7.9020002@gmail.com> |
| Content-Type | text/plain; charset="UTF-8" |
| Date | Thu, 22 Mar 2012 14:12:32 -0400 |
| Mime-Version | 1.0 |
| X-Mailer | Evolution 2.32.3 |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org, Steven Lehar <slehar@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.895.1332439968.3037.python-list@python.org> (permalink) |
| Lines | 67 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1332439969 news.xs4all.nl 6905 [2001:888:2000:d::a6]:37951 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:22036 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Python classes: Simplify? "J. Cliff Dyer" <jcd@sdf.lonestar.org> - 2012-03-22 14:12 -0400
csiph-web