Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bad Cocoa

Bad Cocoa

How-to guide for building the kind of code you will deeply regret later

Delisa Mason

May 28, 2014
Tweet

More Decks by Delisa Mason

Other Decks in Programming

Transcript

  1. Bad Cocoa How to write the code of deep regret

    quickly and easily - @kattrali
  2. Test Private Stuff ensure every test will break during refactors

    maximize the number of mocks, stubs, and performSelector() calls
  3. Use Delegates with Callbacks If you don't need asynchronous callbacks

    for synchronous code, you aren't trying hard enough -initWithDelegate:callback:
  4. Categoriception Extend your own classes with several categories instead of

    containing each unit of related functionality in a single class
  5. Safely assign many responsibilities using protocols @class MyController : NSObject

    <MyControllerDelegate, Why, God, Please, Stop, WithTheProtocols>
  6. Safely assign many responsibilities using protocols BONUS: Make each component

    of a protocol optional, for maximum flexibility and verbosity (and less warnings!!)
  7. Always Swing the Heaviest Hammer NSOperation and Core Data all

    day every day - maximize boilerplate code (GCD and NSCoding don't real)
  8. Make Code Styles Inconsistent increase the difficulty of using or

    extending your project avoid code style tools like clang- format and Uncrustify
  9. When in doubt, add to AppDelegate There is no better

    place to dump bits of code which do not belong anywhere and need access to application state certainly not new classes
  10. #define over static variables get the most of your available

    memory for your numbers, strings, and colors