Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please see this article at Ridiculous Fish (written, I believe, by Cory Doras, an engineer on the AppKit team and also creator of the Fish shell):</p> <p><strong>Array: Our arrays, <em>aren't</em></strong>. <a href="http://ridiculousfish.com/blog/posts/array.html" rel="nofollow">http://ridiculousfish.com/blog/posts/array.html</a></p> <p>You've answered your question already:</p> <blockquote> <p>Yes, you can do this now using the immutable NSArray and NSDictionary instances...</p> </blockquote> <p>The beauty of the Cocoa framework is its simplicity, especially concerning data structures. The idea is that the behind-the-scenes code should determine how to implement the structure, not you. In practice, you only ever need two "types" of data structures: Arrays and Dictionaries (or Maps, if you've come from other languages). Of course, you need many "types" of implementations, but you only really need two ways of accessing your data; if you need more ways, then that's where custom classes and composition come into play.</p> <p>As for your concern of efficiency: don't worry about it. The article by Cory (Ridiculous Fish) reveals that under-the-hood, Apple has already met your terms for efficiency. It is after all just pointers, as Ian Murray pointed out in the comments: everything is reference counted and only copied if necessary. It is most probable that when you "copy" or "mutableCopy" an NSArray or NSDictionary that the underlying data is not actually copied. To see how this could be implemented, see Rob Pike's article on the Go language here: <a href="http://blog.golang.org/slices" rel="nofollow">http://blog.golang.org/slices</a>. I'm almost certain that Cocoa follows a similar pattern, perhaps even to a further extent.</p> <p>Additionally, with the advent of Objective-C "blocks," it is now more and more feasible to program in a functional style <em>à la</em> LISP variants (such as Clojure). In fact, I would highly recommend this and encourage you to continue on this path. It can lead to much stabler, cleaner code if done right.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload