Taming Errors with FunctionalKit

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + Ahruman Jens Ayton 3 months ago
    The code on slide 8 is incorrect. By documented convention, a method which returns an NSError by reference is not required or expected to clear the error on success. Therefore, the result of if (!error) is undefined on success. It should be if (val).
Post a comment
Embed Video
Edit your comment Cancel

3 Favorites

Taming Errors with FunctionalKit - Presentation Transcript

  1. taming errors with FunctionalKit Tuesday 24 March 2009
  2. Error handling in Obj-C ‣ nil ‣ NSError ‣ @throw, and others? Tuesday 24 March 2009
  3. nil Tuesday 24 March 2009
  4. ‣ MyObject *object = [dictionary objectForKey:@”key”]; // Object might be nil. ‣ [object doSomething] => nil Tuesday 24 March 2009
  5. Pros Easy to ignore Safe messaging Tuesday 24 March 2009
  6. Cons Easy to ignore ‘Safe’ messaging Variadic functions (nil termination) Not in the Type - When do you get nils? You don’t have to think about it No error message Tuesday 24 March 2009
  7. NSError Tuesday 24 March 2009
  8. ‣ NSError *error; ‣ id val = [something withObject:object error:&error]; ‣ if (!error) { ... } else { ... } ‣ Or just use val directly. Tuesday 24 March 2009
  9. Pros Easy to ignore Failure messages Clear to the API consumer Tuesday 24 March 2009
  10. Cons (Arguably) dirtier code (Arguably) dirtier selectors I don’t like output parameters Mutable state Tuesday 24 March 2009
  11. So... Tuesday 24 March 2009
  12. Fancy Functional Types Tuesday 24 March 2009
  13. nil → Option Tuesday 24 March 2009
  14. Option - A better nil It fails when messaged explicit handling Tuesday 24 March 2009
  15. single value array Tuesday 24 March 2009
  16. Some value Tuesday 24 March 2009
  17. Or none. Tuesday 24 March 2009
  18. Getting an Option ‣ + (FKOption *)fromNil:(id)maybeNil; ‣ + (FKOption *)fromNil:(id)maybeNil ofType:(Class)cls; ‣ + (FKOption *)some:(id)value; ‣ + (FKOption *)none; Tuesday 24 March 2009
  19. Using an Option ‣ - @property (readonly) BOOL isSome; ‣ - @property (readonly) BOOL isNone; ‣ - @property (readonly) id some; ‣ - (id)orSome:(id)some; Tuesday 24 March 2009
  20. The Code Tuesday 24 March 2009
  21. (value|NSError) → Either Tuesday 24 March 2009
  22. Getting an Either ‣ + (FKEither *)eitherWithRight:(id)value; ‣ + (FKEither *)eitherWithLeft:(id)value; Tuesday 24 March 2009
  23. Using an Either ‣ @property (readonly) FKRightProjection *right; ‣ @property (readonly) FKLeftProjection *left; ‣ @property (readonly) BOOL isLeft; ‣ @property (readonly) BOOL isRight; Tuesday 24 March 2009
  24. Using a Left/Right ‣ @property (readonly) id *value; ‣ @property (readonly) id valueOrOther:(id)value; ‣ - (id)valueOrFailWithMessage:(NSString *)message; Tuesday 24 March 2009
  25. ‘Wrong’ on Left ‘Right’ on Right Tuesday 24 March 2009
  26. The Code Tuesday 24 March 2009
  27. Is it better? Tuesday 24 March 2009
  28. Still have to extract. Can still be noisy. Tuesday 24 March 2009
  29. List of As map:: (a→b)→[a]→[b] List of Bs Function from A to B Tuesday 24 March 2009
  30. Mapping with Option ‣ - (FKOption *)mapWithSelector:(SEL)selector; ‣ - (FKOption *)mapWithSelector:(SEL)selector onObject: (id)object; Tuesday 24 March 2009
  31. The Code Tuesday 24 March 2009
  32. Mapping with Either ‣ - (FKEither *)mapWithSelector:(SEL)selector; ‣ - (FKEither *)mapWithSelector:(SEL)selector onObject: (id)object; Tuesday 24 March 2009
  33. The Code Tuesday 24 March 2009
  34. The Code OR OR Tuesday 24 March 2009
  35. By the way... Tuesday 24 March 2009
  36. Option is a Monad. Tuesday 24 March 2009
  37. Either is a Monad too. Tuesday 24 March 2009
  38. FunctionalKit http://github.com/mogeneration/functionalkit Tuesday 24 March 2009
  39. FunctionalKit ‣ FKOption ‣ FKEither ‣ FKFunction (a->b) ‣ FKEffect (a -> Nothing) ‣ FKP* ‣ FKNewtype ‣ FKMacros Tuesday 24 March 2009
  40. resources http://github.com/mogeneration/ functionalkit http://www.qconlondon.com/london-2009/ presentation/Null+References:+The+Billion +Dollar+Mistake Tuesday 24 March 2009

+ nkpartnkpart, 8 months ago

custom

358 views, 3 favs, 1 embeds more stats

Introducing Option and Either in Objective-C.

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 358
    • 353 on SlideShare
    • 5 from embeds
  • Comments 1
  • Favorites 3
  • Downloads 3
Most viewed embeds
  • 5 views on http://www.praytothemachine.com

more

All embeds
  • 5 views on http://www.praytothemachine.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories