Bad Cocoa
How to write the code of deep
regret quickly and easily
- @kattrali
Slide 2
Slide 2 text
Think Monolithic
ensure changing one part of an
app requires changing them all
Slide 3
Slide 3 text
Long Selector is Best Selector
Slide 4
Slide 4 text
Test Private Stuff
ensure every test will break during
refactors
maximize the number of mocks,
stubs, and performSelector() calls
Slide 5
Slide 5 text
Do Not Write Tests
no worries, the compiler will catch
your bugs
Slide 6
Slide 6 text
Use Delegates with
Callbacks
If you don't need asynchronous
callbacks for synchronous code,
you aren't trying hard enough
-initWithDelegate:callback:
Slide 7
Slide 7 text
Subclass Subclass
Subclass
things will be easy when you need
to swap out superclasses
sometime!
Slide 8
Slide 8 text
Categoriception
Extend your own classes with
several categories instead of
containing each unit of related
functionality in a single class
Slide 9
Slide 9 text
Maximize Responsibilities
Per Class
ensure the difficulty of changing
individual components later
Slide 10
Slide 10 text
Safely assign many
responsibilities using
protocols
@class MyController : NSObject
Slide 11
Slide 11 text
Safely assign many
responsibilities using
protocols
BONUS: Make each component of
a protocol optional, for maximum
flexibility and verbosity (and less
warnings!!)
Slide 12
Slide 12 text
Procrastinate on
Performance
always wait until you have a
problem before opening
Instruments.app
Slide 13
Slide 13 text
if (@"Avoid Static
Analysis")
goto fail;
goto fail;
Slide 14
Slide 14 text
Always Swing the
Heaviest Hammer
NSOperation and Core Data all day
every day - maximize boilerplate
code
(GCD and NSCoding don't real)
Slide 15
Slide 15 text
Make Code Styles
Inconsistent
increase the difficulty of using or
extending your project
avoid code style tools like clang-
format and Uncrustify
Slide 16
Slide 16 text
Do not write
documentation
especially avoid easy-to-use
tooling like appledoc
Slide 17
Slide 17 text
Optimize early
Reduce duplication as soon as
possible, making code less flexible
later
Slide 18
Slide 18 text
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
Slide 19
Slide 19 text
#define over static
variables
get the most of your available
memory for your numbers, strings,
and colors