Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"this': 0.03; 'calculating': 0.09; 'decorator': 0.09; 'second.': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; '@property': 0.16; 'attribute,': 0.16; 'cleanly': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'illustrate': 0.16; 'inclined': 0.16; 'inheritance': 0.16; 'personally,': 0.16; 'slight': 0.16; 'sub-class': 0.16; 'subclassing': 0.16; 'subject:Classes': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'example': 0.22; 'cc:addr:python.org': 0.22; 'example.': 0.24; 'skip': 0.24; '(or': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'properties': 0.29; 'message-id:@mail.gmail.com': 0.30; 'sense': 0.34; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'doing': 0.36; 'method': 0.36; 'two': 0.37; 'performance': 0.37; 'nov': 0.38; 'whatever': 0.38; 'heard': 0.39; 'either': 0.39; 'problems.': 0.60; 'simple': 0.61; 'first': 0.61; 'times': 0.62; 'kind': 0.63; 'situation': 0.65; 'circle': 0.68; 'fact,': 0.69; 'square': 0.74; 'special': 0.74; 'gain': 0.79; 'to:none': 0.92; 'suited': 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:content-transfer-encoding; bh=dr+31QmoFzkGH6vTPxrhCdFs2SEyqLNFG5Eps/3Os4s=; b=crUq+wLkFkrs5ROCFGs49xhT/dfLJeLbJu0GmfZJcZHFRXqDzd7He3RxbGztSrf30d Yp2uytuYEXgbLL6blbJepEibRTM5A/s2RfcheurW8w9BT16JW4B2SkeHjd2rZLD32lBq Pn9wruUrpL/01JpRH6y/XkCOCA7GWWP6/dRpsL4Ni7LIPEfzcVPvgNXQ6JnvGJU7SC3l YUME10V/Q/8O4kRSxnNcM7i/vsZpYzPrjaFuQJsDZWDiQsra8r6bAXd7MrT11jxTe152 mnfhKLaqgiAmrvIDq83tJ0mVmlkbIIMKjWep1DimzfMwJR7GgwHFIMgBVdDMosk9qPkU fVNQ== MIME-Version: 1.0 X-Received: by 10.42.110.195 with SMTP id r3mr26602435icp.12.1414791363996; Fri, 31 Oct 2014 14:36:03 -0700 (PDT) In-Reply-To: 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> Date: Sat, 1 Nov 2014 08:36:03 +1100 Subject: Re: Classes From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414791689 news.xs4all.nl 2907 [2001:888:2000:d::a6]:37693 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80061 On Sat, Nov 1, 2014 at 8:24 AM, wrote: > I've never heard of the Circle-Ellipse problem, and my first instinct to = Rob's post was to ask, why would you want to sub-class Rectangle into a Squ= are class? A square is just a special case of a Rectangle. Attempting tha= t kind of sub-classing would just cause problems. The only thing you gain = is a slight optimization in calculating perimeter by turning two multiplica= tions and an addition into a single multiplication which really wouldn't ha= ve an effect on performance unless you were doing that calculation millions= of times per second. > Yep. A square is indeed a special case of rectangle (and a circle is a special case of ellipse), so it would make sense to have an "is_square()" method (or isSquare or squarep or whatever you want to call it). The hairiness of subclassing either to make the other means it's an unideal example. In fact, I would say the Python @property decorator is less well suited to an inheritance situation than to a chronological change. "This used to be a simple attribute, now it has validation/formatting/logging/whatever." But it's hard to come up with an example to illustrate this cleanly for a student. Personally, I'd be inclined to skip properties altogether; learn about them later, much later, and only if you actually need them. ChrisA