Class Variable Access and Assignment
Steve Holden
steve at holdenweb.com
Sat Nov 5 00:12:05 EST 2005
Paul Rubin wrote:
> Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
>
>>It also allows you to do something like this:
>>
>>class ExpertGame(Game):
>> current_level = 100
>
>
>>and then use ExpertGame anywhere you would have used Game with no problems.
>
>
> Well, let's say you set, hmm, current_score = 100 instead of current_level.
> Scores in some games can get pretty large as you get to the higher
> levels, enough so that you start needing long ints, which maybe are
> used elsewhere in your game too, like for the cryptographic signatures
> that authenticate the pieces of treasure in the dungeon. Next you get
> some performance gain by using gmpy to handle the long int arithmetic,
> and guess what? Eventually a version of your game comes along that
> enables the postulated (but not yet implemented) mutable int feature
> of gmpy for yet more performance gains. So now, current_score += 3000
> increments the class variable instead of creating an instance
> variable, and whoever maintains your code by then now has a very weird
> bug to track down and fix.
>
> Anyway, I'm reacting pretty badly to the construction you're
> describing. I haven't gotten around to looking at the asyncore code
> but will try to do so.
I wouldn't bother. From memory it's just using a class variable as an
initialiser.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list