Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80032

Re: Classes

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
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; 'python.': 0.02; 'python,': 0.02; 'class,': 0.07; 'decorator': 0.09; 'function,': 0.09; 'rewrite': 0.09; 'python': 0.11; 'def': 0.12; 'attribute,': 0.16; 'attribute.': 0.16; 'class)': 0.16; 'complicated,': 0.16; 'fetches': 0.16; 'parentheses': 0.16; 'subject:Classes': 0.16; 'wrote:': 0.18; 'written,': 0.19; 'written': 0.21; 'header:User- Agent:1': 0.23; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'change,': 0.30; 'needed.': 0.30; 'code': 0.31; 'equivalent.': 0.31; 'class': 0.32; 'regular': 0.32; 'updated': 0.34; 'skip:_ 10': 0.34; 'definition': 0.35; 'done.': 0.35; 'objects': 0.35; 'but': 0.35; 'accessing': 0.36; 'should': 0.36; 'members.': 0.37; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'organization': 0.63; 'more': 0.64; 'details': 0.65; 'here': 0.66; 'received:74.208': 0.68; 'price': 0.69; 'age': 0.80; '"just': 0.84; 'decorate': 0.84; 'received:74.208.4.194': 0.84
Date Fri, 31 Oct 2014 13:20:36 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Classes
References <51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com> <545350c3$0$23449$426a74cc@news.free.fr> <bj575ahusmihp1fpm58gmcr2eg0g8k21o6@4ax.com> <mailman.15358.1414766892.18130.python-list@python.org> <m30b2n$gpu$1@reader2.panix.com> <iae75a5j9ec1qv8as3n5bipl2milv6kolm@4ax.com>
In-Reply-To <iae75a5j9ec1qv8as3n5bipl2milv6kolm@4ax.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:WfXpLYyYruk4UpZHteZ1uYeO8vMqZDcDs0jwGU4WJa0 Ttg7rPlPrmH69RhTfZCqoQ2ARlVxTglw0GOhlcpwZgwIuiF9Sa JUMAy3WhQ6lEdFNa0Af7mSBS49GXJoqhJFoMzVbi3jESd7i4OS HTX9sfrInJ15P49eTmsPpqEDE/3QNkO10OB0VG9BAn+uYjU5jd 3v9IE85fkzJhA8imvv5yfzPS7gCcZ78f6ct2wHkZuxD0thEpqo aURwIy7djdxcqJAIGXYrv4zZvHU7AR5WhQmr0y39EOHztel8zi w1kP9jZRqNSeEHp8ldP863bxL9YAmmxYAw88ULuvuJzCYRhwOK rHrVARNCjYdw/Ghka6QM=
X-UI-Out-Filterresults notjunk:1;
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.15362.1414776040.18130.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414776040 news.xs4all.nl 2935 [2001:888:2000:d::a6]:48306
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80032

Show key headers only | View raw


On 10/31/2014 12:31 PM, Seymore4Head wrote:

> In this class, we will follow the practice of accessing the contents
> of objects using methods known as getters and setters. While not
> required by Python, this practice encourages the user of the class to
> manipulates class objects solely via class methods. The advantage of
> following this practice is that the implementer of the class
> definition (often someone other than the user of the class) may
> restructure the organization of the data fields associated with the
> object while avoiding the need to rewrite code that uses the class.
>

Written by somebody who doesn't understand a fundamental point about 
Python. It's just not true that the user would have to rewrite code if 
the implementer change the members.

The Python way of writing getters and setters (if/when you get to that 
stage of a Python class) is through the property decorator or its 
equivalent.

class Pet():
     def __init__(self, ....):
         self.internal details set here

     @property()
     def age(self):
         return some_complicated_expression

And the user of the class fetches this by using

mypet = Pet(....)
hisage = mypet.age

No stupid parentheses needed.  When the class is first written, no work 
is needed.  When it's updated to multiply the internal age by 7, just 
write the function, and decorate it to look like a regular attribute.

More complicated things can be done.  But the point is that the user 
should just get the age, by accessing the age attribute, and if the 
implementation needs to change, it can change.

The time to make a class complicated, is when it needs to be.  And the 
user should not have to pay the price for "just in case."

-- 
DaveA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 16:16 -0400
  Re: Classes sohcahtoa82@gmail.com - 2014-10-30 13:33 -0700
    Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:00 -0400
  Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-30 13:34 -0700
    Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:00 -0400
  Re: Classes Larry Hudson <orgnut@yahoo.com> - 2014-10-30 14:28 -0700
    Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:34 -0400
      Re: Classes sohcahtoa82@gmail.com - 2014-10-30 18:21 -0700
      Re: Classes alister <alister.nospam.ware@ntlworld.com> - 2014-10-31 09:59 +0000
        Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 10:07 -0400
  Re: Classes   "ast" <nomail@invalid.com> - 2014-10-31 10:05 +0100
    Re: Classes   "ast" <nomail@invalid.com> - 2014-10-31 10:18 +0100
      Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-10-31 20:21 +1100
    Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 10:05 -0400
      Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-31 08:47 -0600
        Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 15:49 +0000
          Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:31 -0400
            Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 03:37 +1100
              Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:47 -0400
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 04:02 +1100
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:31 -0400
                Re: Classes Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-31 12:39 -0500
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:57 -0400
                Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 10:40 -0700
                Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-01 11:17 +1300
                Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:06 +1100
                Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-01 00:12 -0600
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 17:32 +1100
                Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-03 00:32 +1300
            Re: Classes Dave Angel <davea@davea.name> - 2014-10-31 13:20 -0400
            Re: Classes Marko Rauhamaa <marko@pacujo.net> - 2014-10-31 19:35 +0200
            Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 17:40 +0000
            Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 18:26 -0400
              Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:09 +1100
      Re: Classes   Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 04:06 +1100
        Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:18 -0400
          Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 10:43 -0700
            Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:18 -0400
              Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:42 -0400
              Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 18:57 -0400
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 19:22 -0400
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 19:32 -0400
                Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-01 12:00 -0400
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-01 12:42 -0400
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-02 09:50 +0000
                Re: Classes Tim Delaney <timothy.c.delaney@gmail.com> - 2014-11-02 21:32 +1100
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-02 12:27 +0000
                Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-02 11:31 -0500
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-03 03:12 +0000
                Re: Classes Dan Sommers <dan@tombstonezero.net> - 2014-11-03 06:29 +0000
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-04 01:10 +0000
                Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-04 18:30 +1300
                Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-03 08:50 -0500
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-04 02:34 +1100
                Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-03 07:47 -0700
                Re: Classes Larry Hudson <orgnut@yahoo.com> - 2014-11-02 14:03 -0800
            Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 07:51 +1100
              Re: Classes sohcahtoa82@gmail.com - 2014-10-31 14:24 -0700
                Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 14:40 -0700
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 08:56 +1100
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 08:36 +1100
          Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 17:43 +0000
    Re: Classes Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-31 14:11 +0000
    Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:49 -0400
      Re: Classes   "ast" <nomail@invalid.com> - 2014-10-31 19:31 +0100
        Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:36 -0400
        Re: Classes Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-31 14:41 -0400
          Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:56 -0400

csiph-web