Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Suggestion: Include more attributes in __init__ constructors #283

@aatle

Description

@aatle

In pymunk, there are many attributes that are typically only set once, immediately after creating the object. Especially Body.position.
Body - position (mass, moment, body_type already included). Also: angle, velocity, angular_velocity
Shape - sensor, density, collision_type, elasticity, filter, friction (offset already included)
Constraint - collide_bodies, max_force, max_bias, error_bias
Space - constructor is fine because only one space is created and the settings are usually left as default

Suggestion:
Add at least some of these attributes as keyword-only parameters with default values to the __init__. The reason why they should be keyword-only is that there is no clear order to these attributes, so they shouldn't be positional.

Reasons to include some of these attributes in the constructors:

  • Settings that are initialized right after creation should intuitively be in the constructor. More pythonic than multiple assignment statements.
  • The constructor signature documents the configurable aspects of the object and also their default values. Currently, one must check the docs to find out default values.
  • Certain non-required attributes such as offset and mass are already included in constructors, but are less common than position, density.

The main reasons to not implement this is to keep the constructor simple and the implementation small.
Also, there may be small performance impacts due to internal calls. It only happens during creation though, and it might be insignificant compared to the overall construction.
The size of object creation code isn't likely to change much, only the layout.

This change is backwards compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions