title: Returning mutable vs. returning immutable (non-member-)objects
body: <p>I hardly ever see the second one used and I wonder why?</p>
  
  <ul>
  <li>Neither would it <strong>break support</strong> for situations where an <code>NSArray</code> is expected (as it's a subclass).</li>
  <li>Nor would it <strong>break encapsulation</strong> by revealing mutable internals.</li>
  </ul>
  
  <p>Under the precondition that it's never a mutable ivar that's returned, <sup><em>(which should be common sense anyway)</em></sup><br>
  I can right now only think of advantages of using the second.  </p>
  
  <ul>
  <li>It actually <strong>is</strong> mutable. And muting is <strong>safe</strong> here, so <strong>why prevent it</strong>?</li>
  <li>No need to call <code>[[[foo fooBar] mutableCopy] autorelease]</code>, which <strong>needlessly allocates additional memory</strong> and <strong>needlessly wastes time</strong>.</li>
  </ul>
  
  <p>Here are the method variations:</p>
  
  <pre><code>- (NSArray *)fooBar {
      NSMutableArray *fooArray = [NSMutableArray array];
      //populate fooArray
      return fooArray;
  }
  
  - (NSMutableArray *)fooBar {
      NSMutableArray *fooArray = [NSMutableArray array];
      //populate fooArray
      return fooArray;
  }
  </code></pre>
  
  <p>I'm asking as <strong>my project has a bunch of methods with the same pattern</strong>.<br>
  And in <strong>most</strong> of the times the <strong>returned array will be modified afterwards</strong> (merged, edited, etc).<br>
  So I think it <strong>should be totally fine</strong> to return <code>NSMutableArrays</code>, yet <strong>nobody seems to be doing it</strong>.</p>
  
  <p><code>NSMutableArray</code>, <code>NSMutableSet</code>, <code>NSMutableDictionary</code>… it's basically the same deal.</p>