Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Code style guide

rsms edited this page Dec 29, 2010 · 17 revisions

Headers

#import vs #include

Since Kod is limited to the Xcode platform and the two compilers GCC and Clang, we prefer the use of #import rather than #include. If you do use #include, make sure to add a header guard in the style described below.

Header File Dependencies

Don't use an #import or #include when a forward declaration would suffice.

When you include a header file you introduce a dependency that will cause your code to be recompiled whenever the header file changes. If your header file includes other header files, any change to those files will cause any code that includes your header to be recompiled. Therefore, we prefer to minimize includes, particularly includes of header files in other header files.

You can significantly minimize the number of header files you need to include in your own header files by using forward declarations. For example, if your header file uses the File class in ways that do not require access to the declaration of the File class, your header file can just forward declare class File; instead of having to #import "foo/file.h".

Clone this wiki locally