Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82469
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mateusz@loskot.net> |
| 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; 'talks': 0.03; 'subsequent': 0.05; 'assign': 0.07; 'attribute': 0.07; 'mentioned,': 0.07; 'method.': 0.07; 'plenty': 0.07; 'method,': 0.09; 'style.': 0.09; 'subject:method': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; "wouldn't": 0.14; 'changes': 0.15; '@property': 0.16; 'agreed,': 0.16; 'arbitrarily': 0.16; 'assignment.': 0.16; 'attribute,': 0.16; 'attributes.': 0.16; 'boolean': 0.16; 'effect.': 0.16; 'foo()': 0.16; 'members)': 0.16; 'read-write': 0.16; 'simplest': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'discussion': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'fine': 0.24; 'java': 0.24; 'question': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'query': 0.26; 'right.': 0.26; 'this:': 0.26; 'pass': 0.26; 'asking': 0.27; 'certain': 0.27; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'related': 0.29; 'dec': 0.30; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '13,': 0.31; '>>>>': 0.31; 'default,': 0.31; 'class': 0.32; 'this.': 0.32; 'received:209.85.212': 0.32; 'cases': 0.33; 'fri,': 0.33; 'actual': 0.34; 'could': 0.34; "can't": 0.35; 'received:209.85': 0.35; 'classes': 0.35; 'december': 0.35; 'something': 0.35; 'case,': 0.35; 'operate': 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'c++': 0.36; 'doing': 0.36; 'method': 0.36; 'thanks': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'similar': 0.36; 'so,': 0.37; 'received:209': 0.37; 'starting': 0.37; 'window': 0.38; 'fact': 0.38; 'pm,': 0.38; '12,': 0.39; 'realize': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'most': 0.60; 'new': 0.61; 'simply': 0.61; 'simple': 0.61; 'such': 0.63; 'more': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'worth': 0.66; 'here': 0.66; 'direct': 0.67; 'side': 0.67; 'between': 0.67; 'default': 0.69; 'obvious': 0.74; 'capture': 0.91; 'subject:skip:w 20': 0.91 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=by3o9OgMG7L/4AZ1w1Rfc8k2t8jRpk2A3dABQXVdPx4=; b=FoNzTTxmFvFcUBDGX8tsRQVK0PV0S1bTZz19pApMI2nvOA7aA9eyKrwlFWic2F5X/n 0IMgn3JCCRT9tKxPYy50w4pvGK6VvnjD5jl2k0hUG2hNtHJ0R06cowXp3T6xmSVffMXQ 3mjIzjZjwEEywUbSa2qeYZ/y4lc5HUCChu/FMT4fCnTjAG+3iMmJoVKYtNctq4teVZH3 HDSzMKKmNEJfy6V43/rh8VVv0vjwCAMVdSeDDjcQAMiFL/Qf9JpwqUq27iy/4efJKCZc 8Kak+nqS3Ls6rxNLRo+9LX+es1j0+Ee/45D0R4s3S2InMRCpz6AVB84WhWkfs8BFgnDG RWSw== |
| X-Gm-Message-State | ALoCoQkH4zN6+YAlKXb/pOvcCXaqjAhjhKVD5AvQZbgPicnq5WGiwj2Gyc6tqhKtRXnEC17p7N8L |
| X-Received | by 10.194.52.37 with SMTP id q5mr30229954wjo.39.1418419637758; Fri, 12 Dec 2014 13:27:17 -0800 (PST) |
| MIME-Version | 1.0 |
| X-Originating-IP | [46.28.50.100] |
| In-Reply-To | <CAPTjJmrzfQFE-vf5neO1VpqF+-FoSO4D+d3C4d-i7OK1jP=oOg@mail.gmail.com> |
| References | <CABUeae-rNeN_dGgkgauNr+-qChXvkgenBmgLbFioe+JDqiT+Hg@mail.gmail.com> <CAPTjJmojWeyB_bv-6Rjzkno6Cb7NiUKo7rt4Th6fvNPOsGv_jQ@mail.gmail.com> <CABUeae9ukrw8iYan+iFj_6-V7LT0MVm+heVDWv7zEkqEAMim+g@mail.gmail.com> <CAPTjJmpOX2pEgJM7AgOWeOge5+H=QNUd2KH9nKC34PBVJSDUYQ@mail.gmail.com> <CABUeae-gKsViJt_bD78rZONDeOHVQ4EG82VDpteeuRpcs+W62w@mail.gmail.com> <CAPTjJmrzfQFE-vf5neO1VpqF+-FoSO4D+d3C4d-i7OK1jP=oOg@mail.gmail.com> |
| From | Mateusz Loskot <mateusz@loskot.net> |
| Date | Fri, 12 Dec 2014 22:26:47 +0100 |
| Subject | Re: is_<whatever_you_are_testing_for> as method or property? |
| To | Chris Angelico <rosuav@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | "python-list@python.org" <python-list@python.org> |
| 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.16929.1418419645.18130.python-list@python.org> (permalink) |
| Lines | 71 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418419645 news.xs4all.nl 2961 [2001:888:2000:d::a6]:35069 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Body-CRC | 2723892804 |
| X-Received-Bytes | 7473 |
| Xref | csiph.com comp.lang.python:82469 |
Show key headers only | View raw
On 12 December 2014 at 22:14, Chris Angelico <rosuav@gmail.com> wrote:
> On Sat, Dec 13, 2014 at 8:03 AM, Mateusz Loskot <mateusz@loskot.net> wrote:
>> On 12 December 2014 at 12:26, Chris Angelico <rosuav@gmail.com> wrote:
>>> On Fri, Dec 12, 2014 at 10:21 PM, Mateusz Loskot <mateusz@loskot.net> wrote:
>>>> I've got several cases which are not obvious to me.
>>>> For instance, class Foo has a boolean attribute, read-write,
>>>> which I see a couple of realisations for possible:
>>>>
>>>
>>> 0) Attribute only.
>>>
>>> class Foo:
>>> pass
>>>
>>> Foo().default = True
>>>
>>> Unless you need something more than this, go with this style. Much simpler.
>>
>>
>> Agreed, in general, but if the question was related to such simple case,
>> I wouldn't bother asking it.
>>
>> I mentioned, setting the new value involves more changes to Foo()
>> instance, so i's not possible to capture it with just an assignment.
>> Hence, the discussion between property vs method.
>
> It's still worth mentioning, for completeness.
Of course, very good point.
> Plenty of people come from C++
That's me.
> or Java and simply don't realize that direct attribute access
> makes fine sense. Your statement here talks about a read-write boolean
> attribute, so starting off with the simplest way of doing that - an
> actual attribute - emphasizes the commonness of this.
Yes, I see your point now.
> So, your subsequent design decisions are based around the fact that
> you cannot simply assign to .default and have it do the right thing.
> Are you even able to set default to False?
Right. The particular case (with is_default and make_default members)
I'm discussing is similar to this:
class Window:
def close(self):
# operate window so it gets closed
@property
def is_closed(self)
# query state of window
> For instance, you might
> have a system where there must always be one "default", and so you
> can't make this one not-default, but you could make a different one
> the default, which will un-default-ify this one as a side effect. In
> that case, a "make_default()" method makes the most sense. But if you
> can independently and cheaply set any instance's default flag, you
> could have the actual attribute, and then a set_default() method,
> which updates it. Plenty of Python classes recommend not arbitrarily
> altering certain attributes.
Yes, makes sense. Thanks for brainstorming those ideas deeper.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: is_<whatever_you_are_testing_for> as method or property? Mateusz Loskot <mateusz@loskot.net> - 2014-12-12 22:26 +0100
csiph-web