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


Groups > comp.lang.python > #7995

Re: What's the best way to write this base class?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ckaynor@zindagigames.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'attributes': 0.05; 'assigning': 0.07; 'character,': 0.07; 'method,': 0.07; 'attribute': 0.09; 'back-end': 0.09; 'subclasses': 0.09; 'this:': 0.10; 'def': 0.12; 'wrote:': 0.14; '(ie,': 0.16; '__init__': 0.16; 'file).': 0.16; 'name):': 0.16; 'resource,': 0.16; 'threw': 0.16; 'possibly': 0.16; 'cc:addr:python-list': 0.17; 'classes,': 0.19; 'header:In-Reply-To:1': 0.21; 'seems': 0.21; 'loop': 0.22; 'cc:2**0': 0.22; 'stuff': 0.22; 'received:209.85.210.174': 0.23; 'received:mail-iy0-f174.google.com': 0.23; 'handles': 0.26; 'parameters': 0.26; 'url:mailman': 0.26; 'classes': 0.26; 'pass': 0.27; 'thanks': 0.28; 'character': 0.29; 'subject:?': 0.29; 'toward': 0.29; 'variables': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; 'url:listinfo': 0.30; 'developers': 0.30; 'player': 0.31; "skip:' 10": 0.32; 'decide': 0.34; 'there': 0.35; 'driven': 0.35; 'subject:What': 0.35; 'using': 0.35; 'determine': 0.36; 'idea': 0.36; 'charset:us-ascii': 0.36; 'probably': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'think': 0.38; 'url:python': 0.38; 'url:org': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'doing': 0.39; 'received:209': 0.39; 'header:Mime-Version:1': 0.39; 'basic': 0.40; 'received:192.168.1': 0.40; 'more': 0.60; 'simply': 0.60; 'header:Message-Id:1': 0.62; 'order': 0.62; 'john': 0.62; 'subject:this': 0.76; 'data-driven': 0.84; 'subject:class': 0.84; 'subject:write': 0.84; 'subject:best': 0.93
References <142e76c3-b304-43ef-af24-919fa6146369@c9g2000yqp.googlegroups.com> <mailman.122.1308411487.1164.python-list@python.org> <fa2ee2a4-f46f-42c7-846c-b854977f9e38@16g2000yqy.googlegroups.com>
In-Reply-To <fa2ee2a4-f46f-42c7-846c-b854977f9e38@16g2000yqy.googlegroups.com>
Mime-Version 1.0 (iPhone Mail 8E401)
Content-Transfer-Encoding quoted-printable
Content-Type text/plain; charset=us-ascii
X-Mailer iPhone Mail (8E401)
From Chris Kaynor <ckaynor@zindagigames.com>
Subject Re: What's the best way to write this base class?
Date Sun, 19 Jun 2011 18:52:50 -0700
To John Salerno <johnjsal@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.166.1308534779.1164.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 82.94.164.166
X-Trace 1308534780 news.xs4all.nl 49181 [::ffff:82.94.164.166]:44590
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7995

Show key headers only | View raw


On Jun 18, 2011, at 9:26, John Salerno <johnjsal@gmail.com> wrote:

> Whew, thanks for all the responses! I will think about it carefully
> and decide on a way. I was leaning toward simply assigning the health,
> resource, etc. variables in the __init__ method, like this:
> 
> def __init__(self, name):
>    self.name = name
>    self.health = 50
>    self.resource = 10
> 
> I never did like the idea of using the parameters if I never intended
> to pass them in...just seems wrong.   :)
> 
> The idea of not using a base Character class at all threw me for a
> loop though, so I need to think about that too!

Having a character class (along with possibly player character, non-player character, etc), make sense; however you probably want to make stuff like health, resources, damage, and any other attributes not be handles by any classes or inheritance in order to allow you to make such data-driven (ie, read from a file). Doing so makes the game much more extendable: using classes, you are likely limited to 5 or 'combinations and a few developers (plus, any designers need to know programming).

A basic way to determine between using subclasses over a data driven approach is: is there significantly different back-end behavior or merely attribute differences.

> --
> http://mail.python.org/mailman/listinfo/python-list

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


Thread

What's the best way to write this base class? John Salerno <johnjsal@gmail.com> - 2011-06-17 21:17 -0700
  Re: What's the best way to write this base class? Chris Angelico <rosuav@gmail.com> - 2011-06-18 14:53 +1000
  Re: What's the best way to write this base class? "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-06-18 03:55 -0700
    Re: What's the best way to write this base class? Tim Chase <python.list@tim.thechases.com> - 2011-06-18 06:24 -0500
      Re: What's the best way to write this base class? "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-06-18 06:37 -0700
        Re: What's the best way to write this base class? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-18 08:51 -0600
  Re: What's the best way to write this base class? TheSaint <nobody@nowhere.net.no> - 2011-06-18 19:04 +0800
  Re: What's the best way to write this base class? Mel <mwilson@the-wire.com> - 2011-06-18 10:22 -0400
  Re: What's the best way to write this base class? Ethan Furman <ethan@stoneleaf.us> - 2011-06-18 08:37 -0700
    Re: What's the best way to write this base class? John Salerno <johnjsal@gmail.com> - 2011-06-18 09:26 -0700
      Re: What's the best way to write this base class? Chris Angelico <rosuav@gmail.com> - 2011-06-19 02:34 +1000
      Re: What's the best way to write this base class? Chris Kaynor <ckaynor@zindagigames.com> - 2011-06-19 18:52 -0700
        Re: What's the best way to write this base class? John Salerno <johnjsal@gmail.com> - 2011-06-19 21:04 -0700
          Re: What's the best way to write this base class? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-20 00:12 -0700
          Re: What's the best way to write this base class? Mel <mwilson@the-wire.com> - 2011-06-20 07:57 -0400
            Re: What's the best way to write this base class? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-20 12:31 -0600
          Re: What's the best way to write this base class? Terry Reedy <tjreedy@udel.edu> - 2011-06-20 13:58 -0400

csiph-web