Code-fu mantra

Lately, I’ve been living by some mantras when it comes to dealing with code and large code bases. Not sure if its for everyone, but it works for me.

This was from a really old Tumblr I had, but felt it was good enough to be republished here.

Lately, I’ve been living by some mantras when it comes to dealing with code and large code bases. Not sure if its for everyone, but it works for me.

This mantras of course pertain to Objective-C and the Mac in general.

  1. Subclass as little as possible, composition is better.
  2. Keep implementation files around 500 lines of actual real code, beyond that, you might want to think of refactoring into logical components.
  3. Group logical components by systems.
  4. Readability trumps “generalization”.
  5. Curly brackets are okay if code blocks are greater than 1 single line of code.
  6. Return as early as possible (Wil Shipley).
  7. Companion to returning as early as possible, try not to nest code blocks 3 levels deep.
  8. Async is not always the best solution (refer to mantra #7).
  9. Design for self containment, but more importantly, in areas of responsibility.
  10. Designing public APIs (things that will not change) will probably give you decoupled objects.
  11. Retain/Release is better than autorelease (until ARC of course).
  12. Protocols are awesome.
  13. Composition of data structures at the expense of space might save you time.
  14. Less objects more primitive types.

Thoughts comments? Eager to hear about yours.