Opened 2 years ago

#5431 assigned task

Public attributes vs. getters and setters

Reported by: Fredrik Magnusson Owned by: Christian Andersson
Priority: major Milestone: Pending
Component: Python Version: trunk
Keywords: Cc:


Much of the Python codebase contains unnecessary getters and setters for class attributes, rather than simply leaving the attributes "public" and letting the user get and set them directly (and introduce properties where needed). It is worth considering whether the Python code should be restructured to get rid of these getters and setters.

Although there are some performance benefits to be gained, the main point is to have Python code that is consistent and Pythonic (and even consistenly Pythonic). See

The current state is that some classes consistently use getters and setters, e.g. pyjmi.ukf.ScaledVariable, others consistently use attributes, e.g. assimulo.solvers.Radar5ODE., and others use a messy mix, e.g. pyjmi.optimization.casadi_collocation.LocalDAECollocator.

It is worth noting that this not only affects existing code. As new classes are created, one may feel inclined to sacrifice pythonicity in favor of consistency with related classes and so spread the use of unnecessary getters and setters.

Since a complete overhaul seems like a lot of work, a compromise is to decide that we avoid unnecessary getters/setters in future implementations, and existing code is adapted when we feel it is appropriate (e.g. during refactorization for other purposes).

Change History (0)

Note: See TracTickets for help on using tickets.