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