-
Notifications
You must be signed in to change notification settings - Fork 191
Description
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
offsetandmassare already included in constructors, but are less common thanposition,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.