Re: red black trees
Re: red black trees
- Subject: Re: red black trees
- From: Todd Blanchard <email@hidden>
- Date: Tue, 24 Feb 2004 21:41:03 -0700
Not to be picky, but your Objective C examples are all examples of
terrible Objective C.
I recommend you take a look at Smalltalk With Style for getting into
the zen of Obj C style naming.
if([a compare:b] == NSOrderedAscending)
could be if([a lessThan: b])
MyType* t1 = [t2 mutableCopy];
[t1 add:t3];
...
[t1 release];
Why would add: not return a new copy in the case of an immutable
object similar to how stringByAppendingString: ?
And otherwise it should return self as in NSMutableArray.
In C++ you can write:
struct MyType {
int value;
MyType (int i) { value = i; }
};
std::vector<MyType> v;
v.push_back(32);
v.push_back(64);
NSMutableArray *v = [NSMutableArray arrayWithObjects:
[NSNumber numberWithInt: 32],
[NSNumber numberWithInt: 64], nil];
Looks about the same.
-Todd Blanchard
On Feb 19, 2004, at 5:11 AM, Allan Odgaard wrote:
On 19. Feb 2004, at 11:29, Marco Scheurer wrote:
Arg... implementing algorithms in ObjC is certainly not something I
would recommend, not really for the performance overhead, but mainly
for the syntactic overhead [...]
Argh! I would have said exactly the opposite, ie one always want to
avoid the syntactic mess of C++. [...]
Not that I wish to start a flame war or anything, but would you care
to elaborate?
I mean, in C++ you compare types like:
if(a < b)
...
In Cocoa/ObjC that is
if([a compare:b] == NSOrderedAscending)
...
In C++ you can write:
MyType t1 = t2 + t3;
In ObjC that would be something like:
MyType* t1 = [t2 mutableCopy];
[t1 add:t3];
...
[t1 release];
In C++ you can write:
struct MyType {
int value;
MyType (int i) { value = i; }
};
std::vector<MyType> v;
v.push_back(32);
v.push_back(64);
In ObjC you would do:
@interface MyType : NSObject
{
int value;
}
@end
@implementation MyType
- (id)initWithInt:(int)i
{
if(self = [super init])
value = i;
return self;
}
@end
NSMutableArray* a = [NSMutableArray array];
[a addObject:[[[MyType alloc] initWithInt:32] autorelease]];
[a addObject:[[[MyType alloc] initWithInt:64] autorelease]];
And so on... not to mention all the standard algorithms available in
C++...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.