Programming Languages – Why Are Objects Passed by Reference?

object-orientedprogramming-languages

A young co-worker who was studying OO has asked me why every object is passed by reference, which is the opposite of primitive types or structs. It is a common characteristic of languages such as Java and C#.

I couldn't find a good answer for him.

What are the motivations for this design decision?
Were developers of these languages tired of having to create pointers and typedefs every time?

Best Answer

The basic reasons come down to this:

  • Pointers are technical to get right
  • You need pointers to implement certain data structures
  • You need pointers to be efficient in memory usage
  • You don't need manual memory indexing to work if you aren't using the hardware directly.

Hence, references.

Related Topic