Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'assign': 0.04; 'instance': 0.05; 'character,': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'to:name:python list': 0.09; '~ethan~': 0.09; 'def': 0.12; 'wrote:': 0.14; 'character:': 0.16; 'creation.': 0.16; 'made,': 0.16; 'name):': 0.16; 'class,': 0.16; 'to:2**1': 0.20; 'header:In-Reply-To:1': 0.21; 'fine': 0.22; 'etc,': 0.23; 'specify': 0.25; 'subject:?': 0.29; 'explicitly': 0.29; 'class': 0.29; 'yet': 0.32; 'to:addr:python-list': 0.33; 'characters': 0.34; 'option': 0.35; 'header:User-Agent:1': 0.35; 'subject:What': 0.35; 'charset:us-ascii': 0.36; 'assigned': 0.37; 'change': 0.37; 'subject:: ': 0.38; 'said': 0.39; 'to:addr:python.org': 0.39; 'john': 0.62; 'here': 0.66; 'received:websitewelcome.com': 0.67; 'received:69.93': 0.67; 'route': 0.67; 'subject:this': 0.76; 'subject:class': 0.84; 'subject:write': 0.84; 'subject:best': 0.93; 'received:gateway02.websitewelcome.com': 0.95 Date: Sat, 18 Jun 2011 08:37:00 -0700 From: Ethan Furman User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: John Salerno , python list Subject: Re: What's the best way to write this base class? References: <142e76c3-b304-43ef-af24-919fa6146369@c9g2000yqp.googlegroups.com> In-Reply-To: <142e76c3-b304-43ef-af24-919fa6146369@c9g2000yqp.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: c-67-170-168-84.hsd1.or.comcast.net ([192.168.74.5]) [67.170.168.84]:1474 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 51 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308411487 news.xs4all.nl 49177 [::ffff:82.94.164.166]:33785 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7912 John Salerno wrote: > 1) > class Character: > > def __init__(self, name, base_health=50, base_resource=10): > self.name = name > self.health = base_health > self.resource = base_resource You said above that health and resource will never be explicitly passed, yet here you have allowed for that possibility. If you are going to have mosters, etc, also inherit from Character, with different health and resources, I would go this route with one change: def __init__(self, name, base_health, base_resoures): and always specify those numbers on creation. > 2) > class Character: > > base_health = 50 > base_resource = 10 > > def __init__(self, name): > self.name = name > self.health = base_health > self.resource = base_resource You do not need to assign health and resource here -- they are already assigned on the class, so the instance will see them automatically. When a change is made, the instance will automagically get its own copy. > 3) > BASE_HEALTH = 50 > BASE_RESOURCE = 10 > > class Character: > > def __init__(self, name): > self.name = name > self.health = BASE_HEALTH > self.resource = BASE_RESOURCE If *all* characters (player, non-player, monster, etc) will have the same base health and resources then this is fine -- otherwise I would use option 1. ~Ethan~