Paradigms in practice
When is object-oriented programming the wrong choice?
On this page
When the dominant operation is a uniform transformation over many records, per-record objects can obscure the algorithm and introduce needless allocation. An array operation over a million samples may be clearer. Measure with a representative workload and consider keeping object boundaries around resources and policy.
Worked example
Pythonreadings_mv = [90, 105, 115, 80]
threshold_mv = 100
excess = [reading - threshold_mv for reading in readings_mv
if reading > threshold_mv]
assert excess == [5, 15]Explore class relationships in the OOP Playground