• 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: red black trees
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: red black trees
      • From: Allan Odgaard <email@hidden>
References: 
 >red black trees (From: Brian Reardon <email@hidden>)
 >Re: red black trees (From: Todd Blanchard <email@hidden>)
 >Re: red black trees (From: Brian Reardon <email@hidden>)
 >Re: red black trees (From: Allan Odgaard <email@hidden>)
 >Re: red black trees (From: Marco Scheurer <email@hidden>)
 >Re: red black trees (From: Allan Odgaard <email@hidden>)

  • Prev by Date: question about NSNaturalTextAlignment
  • Next by Date: Re: Opening NSDocument window in the background
  • Previous by thread: Re: red black trees
  • Next by thread: Re: red black trees
  • Index(es):
    • Date
    • Thread