CodingStyle.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. Being a totally anal coder, and having my own coding style(s) that I have been
  2. using for decades, I am also totally hostile to other coding styles... If you
  3. wish to contribute to this viewer sources, please do comply to the following
  4. rules.
  5. The coding style used in these sources (*.c/*.cpp/*.h/*.inl files) mostly
  6. derives from LL's v1 viewer coding style (I do prefer the K&R style regarding
  7. curly brackets, which is more compact, but it would be too much work to convert
  8. all the source files to it), with personnal adjustments.
  9. All source files are encoded in the ISO8859-1 character set and each line shall
  10. be newline (\n) terminated (i.e. in the UNIX text file standard: no DOS/OS-X
  11. text file or UTF-8/16/whatever-ISO encoding accepted for the sources).
  12. There should be no trailing space or tab in source file lines, and each source
  13. file shall end with an empty line (i.e. a newline character alone on last
  14. line).
  15. Tabs (\t) are *always* 4 spaces wide; any 4+spaces sequence should be replaced
  16. with a tab (\t) character in the sources.
  17. Every source line should, when possible, never be longer than 80 characters
  18. (once all tabs expanded to 4 spaces).
  19. The C++-style comments (//) should be used everywhere, excepted in the License
  20. header block, where the C-style comment (/* <license here> */) shall be used.
  21. Doxygen markers shall not be used (and removed whenever an old source file
  22. containing some is edited).
  23. Names shall be kept short enough to be readable and not cause excessively
  24. verbose code. *Counter* example:
  25. char this_is_not_an_acceptable_variable_name;
  26. Global variables shall be camel-cased and start with a 'g', like this:
  27. extern S32 gSomeGlobalVariable;
  28. Thread-local global variables shall be camel-cased and start with a 't', like
  29. this:
  30. extern S32 tSomeThreadLocalGlobalVariable;
  31. Class and struture member non-static variables shall be camel-cased and start
  32. with a 'm', while static member variables shall start witha 's', like this:
  33. struct
  34. {
  35. char* mStringp;
  36. size_t mStringLength;
  37. static size_t sMaxStringLengh;
  38. };
  39. All classes found in the sources should already be following this rule to the
  40. letter, while many structures have not yet been converted...
  41. Local variables and functions shall be lower-cased. E.g.:
  42. static void some_module_local_function()
  43. {
  44. char* some_local_strp = NULL;
  45. .../...
  46. }
  47. Pointer variable names should end with a 'p' (sadly, there are so many such
  48. variables in the original sources which break this "rule" that I could not
  49. yet change them all to comply). E.g.
  50. extern gGlobaVariablep;
  51. char* local_stringp;
  52. void* mUserDataMemberVariablep;
  53. Class names shall start with either "LL" or the initials of the author,
  54. followed with a capital letter and the camel-cased class name. E.g.
  55. class HBSomeClass
  56. {
  57. .../...
  58. };
  59. This should also apply to struture names, even though there are many stuctures
  60. in the old code I could not yet convert to this rule.
  61. Class (and structure) methods shall be camel-cased and start with a minuscule.
  62. E.g.
  63. class LLSomeClass
  64. {
  65. public:
  66. void someMethod();
  67. };
  68. Variable types shall include the pointer type. E.g. a pointer to a char*
  69. variable shall be declared as:
  70. char* variablep; // The type of variablep is: char*
  71. and *NOT* as:
  72. char *variablep;
  73. When multiple variable pointers are declared, use one line per pointer. E.g.:
  74. char* variablep1 = NULL;
  75. char* variablep2 = NULL;
  76. and *NOT*:
  77. char *variablep1 = NULL, *variablep2 = NULL;
  78. It is perfectly acceptable (and actually preferred) to test for equality
  79. against a constant with a variable as the left member of the test: it is
  80. easier to read and understand this way, and if you are *stupid* enough to
  81. type '=' instead of '==' in the test, then you *deserve* the bug you will
  82. encounter !
  83. E.g.:
  84. if (variable == 0)
  85. {
  86. .../...
  87. }
  88. else if (variable == 1)
  89. {
  90. .../...
  91. }
  92. else
  93. {
  94. .../...
  95. }
  96. is preferred to:
  97. if (0 == variable)
  98. {
  99. .../...
  100. }
  101. else if (1 == variable)
  102. {
  103. .../...
  104. }
  105. else
  106. {
  107. .../...
  108. }
  109. Even though the viewer code is now C++17-compliant, 'NULL' (shorter, already
  110. used everywhere in the original code) is preferred over 'nullptr, excepted
  111. where 'nullptr' is needed to disambiguate the pointer type (which would
  112. otherwise require a static cast in the (Type*)NULL form).
  113. Similarly, static casts are done in the good old (and shorter/easier to read)
  114. C-style. I.e. there should be no 'static_cast<SomeType>(some_variable)' in the
  115. code and you shall instead use: '(SomeType)some_variable'
  116. C 'typedef' is also prefered to C++11 'using', when not used in C++11 templates
  117. requiring the latter; typedef-defined types should be lower-cased and end with
  118. "_t". E.g.
  119. typedef std::vector<std::string> string_vec_t;
  120. .../... More to follow as I think of it...
  121. Henri Beauchamp.