[Bf-committers] Idea: deprecate the attribute access for user properties in the BGE

José Ignacio jose.cyborg at gmail.com
Mon May 25 18:16:27 CEST 2009

Deprecate & remove attribute access for user properties in
KX_GameObject in favor of the recently introduced dictionary syntax.
this: obj.userprop would become: obj["userprop"]

- Dictionary access allows the used of reserved or even illegal python
names (like "for" and "class"), like the GUI and the logic bricks let
you do now (thus being consistent with them), plus preventing name
clashes between these and current/future class attributes. This is
very important for beginners (and maybe even people with some
experience), that would start wondering "why cant i access this
property in python while i can use it perfectly with logic bricks?"
- It is way faster, since it doesn't have to go trough all the python
getattr system and dicts have very fast lookups.
- Also, since names are python strings lets you do things would have
to do with a __getattr() hack
- Typing a class attribute wrong assignation would raise an exception
instead of failing silently. For example, typing
# -----------------------------
obj.poistion = [1, 2.5, 3] # notice the typo
# -----------------------------
would create a property called "poistion" instead of raising an
exception, thus leading to headaches and a lot of time wasting trying
to find the issue. More if we are talking about beginners.

-- love

More information about the Bf-committers mailing list