Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75755
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'subsequent': 0.05; 'attribute': 0.07; 'assumed': 0.09; 'lookup': 0.09; 'subject:method': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; ':-p': 0.16; 'called.': 0.16; 'expensive,': 0.16; 'fancy': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'maintainers': 0.16; 'metaclass': 0.16; 'parentheses': 0.16; 'pythonic': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'cheap': 0.19; "python's": 0.19; 'aug': 0.22; 'coding': 0.22; 'cc:addr:python.org': 0.22; 'decorators': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'wondering': 0.29; 'am,': 0.29; 'generally': 0.29; 'properties': 0.29; 'compared': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'project?': 0.31; 'anyone': 0.31; 'this.': 0.32; 'says': 0.33; 'cases': 0.33; 'style': 0.33; 'could': 0.34; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'acceptable': 0.36; 'object,': 0.36; 'method': 0.36; 'subject:?': 0.36; 'similar': 0.36; 'should': 0.36; 'clear': 0.37; 'being': 0.38; 'christian': 0.38; 'whatever': 0.38; 'anything': 0.39; 'does': 0.39; 'either': 0.39; 'most': 0.60; 'reserved': 0.61; 'simple': 0.61; "you're": 0.61; "you'll": 0.62; 'real': 0.63; 'provide': 0.64; 'more': 0.64; 'anything.': 0.68; 'realized': 0.68; 'helping': 0.70; 'friendly': 0.72; 'unusual': 0.74; 'different.': 0.84; 'subject:Making': 0.84; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=VHNK8GagLOrC90VeQ5BXAtn5f5rXdV0lVNGNrf9uy64=; b=0NjIlO3ktavqoOmCUMZslGToaOIZF7IrPurMaF1BFtPy8nZNHGVi7/VG0Od6WiA3iG c2RP1BovoOArvAgp/4rST+zQmKWnqUBmECJ0wcbLJyNOkfukp1NVqwWUxN7NyRq6wfEW iHF3zNJM9YJ+dbev6NkT6HfqFVv31htKiYaWsuTcsnAdSsV73TDwOWqxxOEz0sogGf8m HefptHkM2fmAt4ri1pCJOLNNKhEZ74Xo5T1YXv4dZNcTpow9e5daCpfi9nZtHKfCKtKB 5gx3rBGC3cvgOnilYDW7DnR6zvb+JuANWNXBhzy0WTNkJAl0Vc+vOMB21OljPP4Njink 8s+w== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.230.212 with SMTP id jn20mr8594936icb.59.1407272171470; Tue, 05 Aug 2014 13:56:11 -0700 (PDT) |
| In-Reply-To | <CA+9L8FypV3+D1cMTca7Dmwju6UB_myDtMUGukpY1fGGZLcbLGQ@mail.gmail.com> |
| References | <CA+9L8FypV3+D1cMTca7Dmwju6UB_myDtMUGukpY1fGGZLcbLGQ@mail.gmail.com> |
| Date | Wed, 6 Aug 2014 06:56:11 +1000 |
| Subject | Re: Making every no-arg method a property? |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12675.1407272179.18130.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1407272179 news.xs4all.nl 2865 [2001:888:2000:d::a6]:39710 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:75755 |
Show key headers only | View raw
On Wed, Aug 6, 2014 at 5:39 AM, Christian Calderon <calderon.christian760@gmail.com> wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place :-P > . I was wondering what other thought of this, is it an overly fanciful way > of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? It's not a Pythonic style of coding. A property is generally assumed to be a cheap and simple lookup that cannot change anything - that is, it should be 'safe'. A no-arg method could mutate the object, could be expensive, could do just about anything. The parentheses make it clear that something's now happening - code's being called. Properties should be reserved for those cases where it's conceptually an attribute lookup, but for whatever reason you need a bit of code on it - and that's a pretty unusual case, compared to zero-argument methods. Strong recommendation that you don't do this. Of course, Python's "consenting adults" policy says that you're most welcome to - but you'll find that it's much more friendly to subsequent maintainers to keep attribute lookup and method call different. ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Making every no-arg method a property? Chris Angelico <rosuav@gmail.com> - 2014-08-06 06:56 +1000
csiph-web