[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

immutability and ==



Following previous discussion of immutability and ==:
If == returns true for equivalent immutable objects, then there should
be a way to specify classes (or properties?) as immutable.  Overriding
== for <tup> and <str> won't be enough.  Also, if a programmer makes immutable
objects, then they will have to remember to override == every time...
which might become a pain.

If they forget, unexpected behavior will occur for anyone that uses
their code.

On the subject, I had a bug in my code recently because of unexpected
behavior:
Let's say I have a vector called 'test'.
If I (as <vec> test), it will return the same object.
If I (as <lst> test), it will return a new object.

If I _always_ want a new object, then I have to (dup) it.  It seems
somewhat wasteful to create two new copies in the second case...

Plus, an unsuspecting programmer may use (as) believing it will always
return a new object.

My opinion is: (as) should always return a new object.  Thoughts?

-- 
Jonathan Hseu <vomjom@vomjom.org, vomjom@debian.org, jh4@cec.wustl.edu>
GPG ID:          5228D713
GPG fingerprint: 220B A4EF 70FE B884 CB38  F93F EA8A 1024 5228 D713