Writing Code

From rootshell wiki

Revision as of 09:39, 8 August 2010 by Salehi (Talk | contribs)
Jump to: navigation, search


This page belongs to Turned On Ventures Guideline Series.

Some common practices are mentioned here, for detailed information please refer to Naming and Memory Management sections.


Clean Code

To make code more managed and human readable, please group related methods with #pragma mark dialect. For example put all interface builder methods in .m files under the following lines:

#pragma mark -
#pragma mark IBAction methods

Typographic Conventions

  • The name of a class should contain a noun that clearly indicates what the class (or objects of the class) represent or do. The name should have an appropriate prefix.
    FBConnect for a facebook related class
  • For method names, start with a lowercase letter and capitalize the first letter of embedded words. Don’t use prefixes.
  • For names of functions and constants, use the same prefix as for related classes and capitalize the first letter of embedded words.
    NSRunAlertPanel or NSCellDisabled 
  • Avoid the use of the underscore character as a prefix meaning private, especially in methods. Apple reserves the use of this convention.


Define each protocol in a separate .h file. Explain what each method in protocol does, the return value(s), and etc. Distinguish optional methods with @optional tag.

Safe Coding

Please always embed conditionals withing braces, even when they're consisted of only one line.
The following is wrong:

        [self.delegate checkNotFound]; 

Instead use:

        [self.delegate checkNotFound]; 


Please add DEBUG flag to your Xcode build configurations (debug only) to log required information. Go to your Target or Project settings, find the setting named "Preprocessor Macros" or if it's not present, click the Gear icon at the bottom left, select "Add User-Defined Setting". The new setting name should be GCC_PREPROCESSOR_DEFINITIONS, and you can type your definitions in the right-hand field .

constant_1=VALUE constant_2=VALUE

Note that you don't need the '='s if you just want to #define a symbol, rather than giving it a value (for #ifdef statements)

When implementing a method, always add the following at the start of the method:

#ifdef DEBUG 

You may also add the method's arguments to this line.

HierarchyPrevious.gif Programming

Copyright Turned On Ventures 2010, turnedonventures.com

Personal tools