Chess code style

File


All the functionality must be put into one or more .cpp and .hpp files into the appropriate module of chess, or a new module should be created if the contributed functionality is a rather large piece of code, or if it does not fit any existing module.

  • All the file names are written in lower case for better compatibility with both POSIX and Windows.
  • C++ interface headers have .hpp extension
  • Implementation files have .cpp extension
  • The implementation is put to chess/<module_name>/src, interface is added to the header files in chess/<module_name>/include/. There is no need to add the files to the module explicitly, just rerun CMake and it will add the files automatically.

File Structure


Every source file, except for the samples, starts with BSD-compatible license, which template can be found here. The extra/different copyright clauses are possible, as long as the license stays BSD-compatible.
Other rules for both header and implementation files include:

  • All the functionality must be put into chess namespace, or, possibly, some nested namespace, e.g. chess::eye
  • Code lines should not be very long. Normally, they should be limited to 100 characters.
  • No tabulation should be used. Set your editor to use spaces instead.
  • Only English text is allowed. Do not put comments or string literals in other languages.
  • Indentation is 4 spaces.
  • Header files must use guarding macros, protecting the files from repeated inclusion:
    #ifndef _CS_your_header_name_HPP_
    #define _CS_your_header_name_HPP_ 
    #ifdef __cplusplus
    namespace CS { namespace mynamespace {
    ...
    }}
    #endif
    #endif
  • Source files must include precomp.hpp header before other headers, in order to make precompiled headers mechanism in Visual C++ work properly.

Designing functions and class interfaces


Functionality

The functionality must be well defined and non-redundant. The function should be easy embedded into different processing pipelines that use other chess functions.

Name

The name should basically reflect the function purpose. There are a few common naming patterns in chess:

  • Majority of function names have form:
posted @ 2014-11-18 18:45  Lcnoctave  阅读(233)  评论(0)    收藏  举报