Consistency of style is especially important in Lucy because multiple programming languages are involved. Virtually no contributors are likely to be equally fluent in all of them, and it is easier for those who are less fluent in a given language to comprehend code that adheres to a single style.
Contributions should conform to the following set of guidelines. Individual guidelines may be broken if necessary to achieve a clearer layout.
All Languages
Pronounceable identifiers are preferred over nms_wth_vwls_rmvd (names with vowels removed), as they are easier for non-native English speakers to parse.
C
All C code should follow the guidelines spelled out in the Apache HTTPD C Style Guide: http://httpd.apache.org/dev/styleguide.html.
In addition, contributions should use these naming conventions:
- Module file names
UpperCamelCase.
./src/c/Lucy/Util/BitVector.h
- Struct definitions
UpperCamelCase. Globally visible struct definitions are prefixed by 'lucy_'.
lucy_BitVector
- Variables
- Lower case with underscores. Globally visible variables are prefixed by 'lucy_'.
bit_vec
- Lower case with underscores. Globally visible variables are prefixed by 'lucy_'.
- Functions
- Lower case with underscores. Globally visible functions are
prefixed by 'lucy_NickName_', where NickName is a shortened version of the name of the module where the function is located. Special global functions defined in Globals.h omit 'NickName_' (though they are still prefixed by 'lucy_').
lucy_BitVec_destroy
- Lower case with underscores. Globally visible functions are
- Macros
- Mixed case, starting with a capital letter, multiple words
separated by underscores. Prefixed with 'Lucy_NickName_' if globally visible.
Lucy_BitVec_Next_Set_Bit
- Mixed case, starting with a capital letter, multiple words
- Constants
- All upper case with underscores. Prefixed with LUCY_NICKNAME_ if globally visible.
LUCY_BITVEC_SENTINEL
- All upper case with underscores. Prefixed with LUCY_NICKNAME_ if globally visible.
Perl
All code should follow perlstyle.
Formatting is handled automatically using the app $DIST_ROOT/devel/lucytidy, which is perltidy with a preference set derived from guidelines laid out in Damian Conway's book 'Perl Best Practices'.
Ruby
All code should follow the guidelines set out here:
Spaces should be used for indentation. Curly braces should be used for one-line blocks, do ... end for multi-line blocks.
File naming should follow these conventions:
BitVector class => bit_vector.rb
Lucy module => lucy.rb
Lucy::BitVector class => lucy/bit_vector.rb
All code should be wrapped in the Lucy module. Public methods should include rdoc comments.