Skip to content

Replace getters and setters (where possible) by property or direct access #134

@PgBiel

Description

@PgBiel

We should replace getters and setters, which are an antipattern in Python (as exposed on #122 (comment)). Most of them can be replaced either by:

  1. The use of @property (which allows custom code to run when access is attempted or an assignment is done);
  2. Direct access to the attribute (i.e. just delete the get and set functions where they don't do anything at all besides just getting or setting).

As I exposed in #122 (comment), rather than having a set function for each attribute, we should (also) implement a general set function for dataclasses, which allows us to set multiple attributes at a time (and also to animate such setting), like so:

mobj.set(x=5, y=6, z_index=50, ...)

Setter functions which require more than one parameter could be kept anyways, and then simply invoked by .set when required.

Suggestions? Ideas?

Relevant PRs and comments (if there are more, please tell me or just edit this post): #122 (comment), #122 (comment), #116, #114

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorRefactor or redesign of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions