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

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


On Mon, May 25, 2009 at 1:16 PM, José Ignacio <jose.cyborg at gmail.com> wrote:
> Proposal:
> 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"]
>
> Rationale:
> - 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.
>
sorry, the last argument has some mistakes, should read as follows:

- With the attribute access removed, typing a class attribute wrong
in an assignation operation would raise an exception instead of
failing silently.
For example, typing in the current engine:
# -----------------------------
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
> cyborg_ar
>


More information about the Bf-committers mailing list