[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Python property conventions in my new Sprite class
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Python property conventions in my new Sprite class
- From: Sagie Maoz <sagie@xxxxxxxxx>
- Date: Mon, 30 Jul 2012 21:53:33 +0300
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 30 Jul 2012 14:53:14 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; bh=eaCChOeDbEPxlGRO8UA5GC8XVLBsRO9p6iEDJRrOzDg=; b=JYYvAIvbk7IclniYqaCVcGZhwayJdlrR2b+KetBe5jIqZ64Zq4m537P7LEXU3tNvdT O/zxT5m1d9xly7/a2GFBzWGafrjdGYxUw/k7+CgWLrHbrMiIGi9Bw0deLadt2pRR4JVc lAvhmRlcsL0k3cqoZRHCbZjrPGI9hTp1j3N+hhGeWTAmpPHbcm22zSyKx0a/0tTR3s4U p0eQT3eZBELikXO0d6ICSuHs5Be1+47LYafWeglgJEjFXuXItTt2RCw398eYv3zhk6an B6vcw4CN1/7Nggh1veNEwWHooOKaKOsvzhdXOBrraaaaov03OKCZNLvZwLDb30jVbgRL /Jww==
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I would like to have your opinion on some decisions I made when writing a new Sprite class, as part of my Summer of Code project .
As part of this work. I wrote several new features related to the core Sprite class, which can be set and manipulated through new attributes of the class.
You can read about the new attributes and my implementation on my blog .
I've decided to make use of Python's properties feature  to have more control on these attributes, and apply some calculations in their getters and setters.
It would be awesome if any of you share your opinion on this approach of using methods instead of directly accessing class attributes.
I couldn't find any benchmarking data online and figured I'd write a profiling suite eventually.
This is the sprite code as of now:
There's still some work to be done there, namely caching (memoizing) the getters' value to avoid unnecessary calculations between frames.
Thanks in advance,