Skip navigation.
 
mlRe: Best Practice for Returning Immutable Objects?
FROM : Kyle Sluder
DATE : Tue Jun 03 22:25:25 2008

On Tue, Jun 3, 2008 at 3:07 PM, Seth Willits <<email_removed>> wrote:
> I used to think that. Now I'm converting to making sure it truly is
> returning an immutable object. There have been cases where I've changed it
> under myself and run into problems. I figure if it says it's immutable, it'd
> better be immutable.


I always do [[mutableInstance copy] autorelease] for two reasons:
1) I told you I've given you an immutable object.  The other portions
of my code had better be able to rely on that object's immutability.
2) It is not my responsibility to optimize creating immutable
instances out of mutable instances.  If it can be done, it is the
mutable class's implementor's problem.  (Of course that might be "me"
the person, but it isn't "me" the client of the mutable class.)

--Kyle Sluder

Related mailsAuthorDate
mlBest Practice for Returning Immutable Objects? Karl Moskowski Jun 3, 17:56
mlRe: Best Practice for Returning Immutable Objects? Shawn Erickson Jun 3, 18:08
mlRe: Best Practice for Returning Immutable Objects? Mike Abdullah Jun 3, 18:13
mlRe: Best Practice for Returning Immutable Objects? j o a r Jun 3, 18:15
mlRe: Best Practice for Returning Immutable Objects? Karl Moskowski Jun 3, 18:16
mlRe: Best Practice for Returning Immutable Objects? Bob Warwick - Code… Jun 3, 18:17
mlRe: Best Practice for Returning Immutable Objects? Karl Moskowski Jun 3, 18:20
mlRe: Best Practice for Returning Immutable Objects? Graham.Lee Jun 3, 18:23
mlRe: Best Practice for Returning Immutable Objects? Karl Moskowski Jun 3, 18:28
mlRe: Best Practice for Returning Immutable Objects? Hamish Allan Jun 3, 18:52
mlRe: Best Practice for Returning Immutable Objects? Seth Willits Jun 3, 21:07
mlRe: Best Practice for Returning Immutable Objects? Kyle Sluder Jun 3, 22:25
mlRe: Best Practice for Returning Immutable Objects? Michael Ash Jun 4, 04:33