Writing Code

From rootshell wiki

(Difference between revisions)
Jump to: navigation, search
(Implementation Steps)
(Documentation)
 
(One intermediate revision not shown)
Line 54: Line 54:
</pre>
</pre>
You may also add the method's arguments to this line.
You may also add the method's arguments to this line.
 +
 +
== Documentation ==
 +
 +
We use "Doxygen" as a documentation tool, which takes comments from inside your code and generates an HTML file and a DocSet (file used in XCode). Luckily Doxygen uses the same syntax as JavaDoc and other popular documentation generator tools. For more information refer to:
 +
 +
[http://www.stack.nl/~dimitri/doxygen/download.html#latestsrc Download Doxygen]
 +
 +
[http://www.stack.nl/~dimitri/doxygen/docblocks.html Doxygen Syntax]
 +
 +
[http://developer.apple.com/tools/creatingdocsetswithdoxygen.html Using Doxygen with XCode]
 +
{{SuperMonkoFooter}}
{{SuperMonkoFooter}}

Latest revision as of 12:17, 13 March 2011

Development

Index

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.

Contents

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.
    fileExistsAtPath:isDirectory:
  • 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.

Protocols

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:

if(!notFound) 
        [self.delegate checkNotFound]; 

Instead use:

if(!notFound){ 
        [self.delegate checkNotFound]; 
}

Implementation Steps

When implementing a piece of program consisting of different parts, first implement the bare minimum functionality, test it to make sure it works, then move to next one. This way, when encountered to the problem, you'll most probably know where to look for.

Debugging

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 
      NSLog(@"[THE CLASS NAME]->[THE METHOD NAME]");
#endif

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

Documentation

We use "Doxygen" as a documentation tool, which takes comments from inside your code and generates an HTML file and a DocSet (file used in XCode). Luckily Doxygen uses the same syntax as JavaDoc and other popular documentation generator tools. For more information refer to:

Download Doxygen

Doxygen Syntax

Using Doxygen with XCode




HierarchyPrevious.gif Programming


Copyright Turned On Ventures 2010, turnedonventures.com

Personal tools