Class Variable Access and Assignment

Paul Rubin http
Sat Nov 5 05:41:31 CET 2005


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.



More information about the Python-list mailing list