[FAQ] What is call-by-value and call-by-reference? (AKA pass-by-value and pass-by-reference)

Pages: 123
rm is a reference. Depending on the compiler and the situation, that means rm either holds a pointer, or that rm is an alias name for m.

It is not just useful, the notion of the identity of an object is fundamental to object-oriented programming.


My limited C++/Java/Scala programming experience tells me something different. It might be fundamental in theory, but in practice notion of pointer-based identity is very rarely useful and more often than not, relying on it is harmful.
> It might be fundamental in theory, but in practice notion of pointer-based identity is very rarely useful and more often than not, relying on it is harmful.

Without a clear notion of object identity and the ability to check for it, we wouldn't even get started.

Without a check for object identity, how would one write a copy-constructor? An overloaded assignment operator? A smart pointer? A garbage collector? A weak reference? Any meaningful code at all?
Last edited on

Without a check for object identity, how would one write a copy-constructor?


Identity checks aren't generally necessary for copy constructors.

An overloaded assignment operator?


Same thing

A smart pointer? A garbage collector? A weak reference?


Etc, etc, etc. None of this is directly related to OOP by the way.
You need to make sure that auto-assigment works. An easy way is if( this==&b ) return *this;
It's an easy way to do it, yes, but it's not needed which is what I was arguing against (well, not arguing, actually I was just stating things, but that's what JL did so...).
> None of this is directly related to OOP by the way.

Object identity and the ability to check for equivalence of identities of objects is fundamental to life. It is a vital concept that existed much before object-oriented programming, or any kind of programming was conceived of.

The the number plate of a vehicle, an account number in a bank, a social security number are all providers of object identity. The concept is fundamental to object-oriented and every other kind of programming because it is not merely an artifact of the solution domain - just an easy way to do something; it is fundamental to the problem domain.

The only part that is an artifact of the solution domain is that the equivalence of object identities can be very efficiently checked using an address, an object reference, an offset into a file and so on (provided the program is not distributed). To the life-time of an object is over, we need to identify the object and we provide the identity of the object to be deleted through an address delete pointer ; alternatives would have been far less efficient. In a distributed environment something like a universally unique identifier (uuid) or a uniform resource identifier (URI) are used to provide object identity.
Last edited on
Topic archived. No new replies allowed.
Pages: 123