• 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
is this badly written code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

is this badly written code?


  • Subject: is this badly written code?
  • From: "Adam Gerson" <email@hidden>
  • Date: Mon, 14 Apr 2008 22:53:16 -0400

In cocoa its very tempting to write a single line of code like:
NSManagedObject *selectedTreeObject = [[[[[self delegate]
mainWindowController] treeController] selectedObjects]
objectAtIndex:0];

or to flush it out in to individual lines:

NSWindowController *mainWindow = [[self delegate] mainWindowController];
NSTreeController *treeController = [mainWindow treeController];
NSArray *selectedTreeObjects = [treeController selectedObjects];
NSManagedObject *selectedTreeObject =  [selectedTreeObjects objectAtIndex:0];

I am looking for some guidance on best practices in a situation with a
lot of nested calls like this. If ultimately the only value I care
about is the final one, selectedTreeObject, whats the best way to go
about getting it? I know "best" is a subjective word. Interested to
hear all of your opinions.

Adam
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: is this badly written code?
      • From: Jeff LaMarche <email@hidden>
    • Re: is this badly written code?
      • From: Adam Leonard <email@hidden>
    • Re: is this badly written code?
      • From: Ferhat Ayaz <email@hidden>
    • Re: is this badly written code?
      • From: "Michael Ash" <email@hidden>
    • Re: is this badly written code?
      • From: Michael Vannorsdel <email@hidden>
    • Re: is this badly written code?
      • From: John Stiles <email@hidden>
  • Prev by Date: Re: Basic Core Animation question
  • Next by Date: Re: "hooking" into another app
  • Previous by thread: Re: Cannot Remove Observer Error [The Quest Continues]
  • Next by thread: Re: is this badly written code?
  • Index(es):
    • Date
    • Thread