• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mutability
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mutability


  • Subject: Re: Mutability
  • From: Julien Dufour <email@hidden>
  • Date: Wed, 21 Nov 2001 06:59:05 +0100

On Wednesday, November 21, 2001, at 05:43 AM, Angela Brett wrote:

Why do you care??

If you need a mutable version of a collection make a mutableCopy of it.

That's true, but consider the case where the object is deep in nested NSArrays or NSDictionaries. Assuming the object is immutable means you have to add the mutableCopy of it to its parent array/dictionary in place of the original object, and if you don't know whether the parent is mutable or not you'll also have to make a mutableCopy of that and add it to its parent, and so on until you get to the 'root' object. That's quite a lot of unnecessary steps if the original objects were actually mutable anyway and you didn't know it. Or perhaps this post is all newbie nonsense. :)

I think you have a wrong approach. You shouldn't have to test whether or not objects you manipulate are mutable version. Your code should "know" what kind of object it manipulates. If you are working in a structure that you may modify, the objects composing it should be NSMutableXXX instances. The involved code has requirement (it need to be able to modify what it is given), you have to respect them.

If the structure you manipulate is providen by some code you haven't written (let's say propertyListFromXMLData), the documentation should let you know what kind of objects you get. If not or if the objects are not mutable, just build a copy of the structure (with mutable objects) and work with it.

You are currently deteriorating your code with operations that could easily be done (and should be done) elsewhere, where information is available.

-- Angela Brett email@hidden http://acronyms.co.nz/angela
A mathematician is a machine for turning coffee into theorems -- Paul Erdos
--
Julien Dufour


  • Follow-Ups:
    • Re: Mutability
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Mutability (From: Angela Brett <email@hidden>)

  • Prev by Date: Re: Rects and points...
  • Next by Date: Clicking dock icon opens window
  • Previous by thread: Re: Mutability
  • Next by thread: Re: Mutability
  • Index(es):
    • Date
    • Thread