Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'alias': 0.09; 'cc:addr:python-list': 0.11; '"is': 0.16; '*any*': 0.16; '8:40': 0.16; '@property': 0.16; 'any.': 0.16; 'choice,': 0.16; 'extraneous': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inheritance': 0.16; 'non-trivial': 0.16; 'repr()': 0.16; 'subclass': 0.16; 'subject:Classes': 0.16; 'tweak': 0.16; 'demonstrate': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'example': 0.22; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'example.': 0.24; 'instance,': 0.24; 'cc:2**0': 0.24; '(for': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'member.': 0.30; 'message- id:@mail.gmail.com': 0.30; 'agreed.': 0.31; 'probably': 0.32; 'quite': 0.32; "can't": 0.35; 'except': 0.35; 'tool': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'useful': 0.36; 'implement': 0.38; 'nov': 0.38; 'truly': 0.60; 'most': 0.60; 'new': 0.61; 'times': 0.62; 'making': 0.63; 'kind': 0.63; 'such': 0.63; 'more': 0.64; 'square': 0.74; 'article': 0.77; 'belief': 0.84; 'exercise,': 0.84; 'get/set': 0.84; 'to:none': 0.92; 'choice.': 0.93 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=cOKNBEU9ax2EVnScw/DpoIx1QJ/sCeu9F2YPCd/8nfM=; b=QYmfnsU6Bjfdhdm6iHVNed/SXlzsi0nhWajK1RlE7ftzZcJ0oQ/ON3ViD1sEcMuO8q AYCYejiyNoQoY2Bi/B1Ma9MvTAAJqSkDhMhiBPpn5CygfU4IujMK75NxxKcqMWbnEynC vQJFhSWdyrCRp2WG5pah/N7qB1X7YuIgkg5Gr3VVibNBgSfhe7t0iZ2SjbI0RXfhrGoe PQb7ClOIomQsa9yLLzcA3gDTnBYGqVHeJTtoj8+lyGy0B/N2kVf/HHtYwOXK4F+QIq9g 12m9OnyOlo7Gx89GSVOcpGWCwysEigaMfnaSb9jH+lNpb8f1ZGw0BKbdW7vArrlEzcvT OLPA== MIME-Version: 1.0 X-Received: by 10.50.164.233 with SMTP id yt9mr60475igb.2.1414792578881; Fri, 31 Oct 2014 14:56:18 -0700 (PDT) In-Reply-To: <20141031144045.05965228@rg.highlandtechnology.com> References: <51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com> <545350c3$0$23449$426a74cc@news.free.fr> <5453c1a6$0$12981$c3e8da3$5496439d@news.astraweb.com> <7pg75alj1qn97hlirk81f7nqd265emgu05@4ax.com> <20141031104319.02e1ca6f@rg.highlandtechnology.com> <20141031144045.05965228@rg.highlandtechnology.com> Date: Sat, 1 Nov 2014 08:56:18 +1100 Subject: Re: Classes From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414792587 news.xs4all.nl 2907 [2001:888:2000:d::a6]:43148 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80062 On Sat, Nov 1, 2014 at 8:40 AM, Rob Gaddi wrote: > For this specific exercise, a Square is a subclass of Rectangle because > the point of Rectangle is to demonstrate that extraneous get/set > functions are completely unnecessary in Python. The point of > Square is to demonstrate that get/set functions can be useful in > certain circumstances where you need to implement non-trivial behaviors, > such as making the "width" property into an alias for the "length" true > data member. As the Wikipedia article explains, this has its own consequences. A reasonable test suite for Rectangle would quite probably fail if given a Square. Hence my belief that this makes for a less-than-ideal example. But I can't think of *any* good example of @property for a tutorial. ANY. > As a learning tool for thinking about inheritance hierarchies it's kind > of rubbish. But then again, most inheritance hierarchies are ambigious > at best, which is why "has a" is often a better choice than "is a". Agreed. There certainly are times when "is a" is the right choice, but there are a lot more times when "has a" is the better choice. Usually, when I subclass, it's because I want to tweak the behaviour of an existing type (for instance, subclass int and change its repr() to return hex(self)), so it really truly is a , in every way except that one tiny change. Otherwise, new type with a member. Much simpler. Much safer. ChrisA