• 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: Allan Odgaard <email@hidden>
  • Date: Wed, 25 Feb 2004 07:46:21 +0100

On 25. Feb 2004, at 5:41, Todd Blanchard wrote:

Not to be picky, but your Objective C examples are all examples of terrible Objective C.
[...]

Are you not exaggerating a bit? The compare: is from the Cocoa API.

To not use the var-args array constructor but adding the elements one-by-one was a) because they may be unknown at construction time and b) the point of that example was to show that it takes ~9 lines to introduce even the simplest type (which you removed from yours) and similarly long constructs to create instances -- I could have used NSNumber instead of my type, but often in algorithmic programming (which was the topic) you need to introduce your own (simple) types! and I could have added a similar (numberWithInt:) class method which use the autorelease pool for easier construction, but that is still not even close to C++'s stack-allocation and/or implicit construction from another type (and it has run-time overhead which you often cannot afford in algorithmic programming).

The add: I agree was stupid -- my intent here was really closer to append, like this:
NSMutableString* str = [NSMutableString string];
for(int i = 0; i < 10; i++)
{
unichar ch = next_char();
NSString* tmp = [NSString alloc] initWithBytes:&ch length:1];
[str appendString:tmp];
[tmp release]; // no release pool because we are in a loop
}

Compared to:
vector<unichar> v;
generate_n(back_inserter(v), 10, next_char);

Or (w/o using a standard algorithm):
wstring str;
for(int i = 0; i < 10; i++)
str += next_char();

You may find other ways to achieve the same in ObjC, and you may argue that it is an unnatural example, but I do not think it changes my original point: that ObjC is really bad at algorithmic programming because of the amount of syntactic overhead.
_______________________________________________
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: Ethan John <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>)
 >Re: red black trees (From: Todd Blanchard <email@hidden>)

  • Prev by Date: Re: access to DOM from the WebKit
  • Next by Date: Re: access to DOM from the WebKit
  • Previous by thread: Re: red black trees
  • Next by thread: Re: red black trees
  • Index(es):
    • Date
    • Thread