Is “pass by reference” bad design? [closed]

Object-oriented programming is done best if you structure your code into clean, understandable abstractions.

Numbers, as an abstraction, are immutable and have no identity (i.e. a “five” is always a “five” and there is no such thing as “multiple instances of five”).

What you’re trying to invent is a “mutable number” which is mutable and has identity. This concept is a bit unwieldy, and you’d probably be better off with modelling your problem with more meaningful abstractions (objects) than that.

Think in objects that represent something and have a specific interface, rather than in individual lumps of values.

Leave a Comment