News for hackers. Stuff that matters.
Re:Cocoa's NSMutableArray changes implementation based on th... by rchowe on Wednesday April 06, 2011 @12:43AM (#2413935)
NSArray/NSMutableArray are class clusters - meaning that upon allocation/initialization they choose between many classes (and it might swizzle the class pointer to be of type NSArray/NSMutableArray, I can't remember).

What's interesting to me is that this uses the standard Objective-C [[class alloc] init] mechanism, which is more intuitive than using a nonstandard class method (because in most other languages new will only allocate one class). When you look at Apple's (NeXTStep's) APIs, there's a lot of evidence of thought in the design process there.

Re:Cocoa's NSMutableArray changes implementation based on th... by masklinn on Wednesday April 06, 2011 @12:59AM (#2413961)
> because in most other languages new will only allocate one class

Now that's simply not true.

In C++-derived languages it will (and mandates that a new object be created to boot), and C++-derived languages are the most common for Enterprise Programming, but that's a far cry from "most other languages".

Re:Cocoa's NSMutableArray changes implementation based on th... by ajg1977 on Wednesday April 06, 2011 @01:44AM (#2414055)
There's nothing special about this. I've written numerous classes in C++/C# that return a single object to the creator but instantiate or swap between different impl classes based on usage patterns.
Re:Cocoa's NSMutableArray changes implementation based on th... by rchowe on Wednesday April 06, 2011 @08:37PM (#2417693)
What I'm saying is that you can't do something like this in C++-derived OO languages

    class Test
    {
        Test( int count ) {
            if ( count > 5000 ) return new Implementation();
            return new OtherImplementation();
        }
    }
you'd have to use a class method, whereas you can do that with the standard alloc/init in Objective-C.
Re:Cocoa's NSMutableArray changes implementation based on th... by blub on Wednesday April 06, 2011 @04:33AM (#2414355)
This is trivially done in C++ with a private implementation. It doesn't matter that you can only allocate one class, that class can allocate whatever it wants to in turn.