Re: is this badly written code?
Re: is this badly written code?
- Subject: Re: is this badly written code?
- From: Matt Burnett <email@hidden>
- Date: Mon, 14 Apr 2008 22:15:12 -0500
Have you thought of using KVC? It makes that code alot smaller, and
(im 99% sure) it deals with things like if treeController returned nil
instead of a NSArray.
NSManagedObject *selectedTreeObject = [self
valueForKeyPath
:@"delegate
.mainWindowController.treeController.selectedObjects.lastObject"];
On Apr 14, 2008, at 10:05 PM, John Stiles wrote:
The chained approach is tempting since it's short and convenient, so
if the code is not prone to failure, I'd say go for it.
If you expect that you might need to see intermediate values in the
debugger or there are weird edge cases where something might return
nil, I'd break it out into multiple lines.
This is really a matter of personal preference so YMMV here.
Adam Gerson wrote:
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
_______________________________________________
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
_______________________________________________
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