HACKING.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ----------------------------
  2. ManaPlus Hacking Guide
  3. ----------------------------
  4. With multiple coders working on the same source files, there needs to be a
  5. standard specifying how code is written down. Not doing so can cause quite some
  6. annoyance for certain coders and easily creates more version conflicts than
  7. necessary.
  8. * Indentation:
  9. Code is indented using 4 spaces, no tabs.
  10. * Line length:
  11. Should not exceed 79 characters.
  12. One reason for this is to keep code readable. In such cases it would often be
  13. better to spread the line over multiple lines or use some extra temporary
  14. variables. Another reason is that some of us are using editors that default
  15. to an 80 character wide screen, and often put two instances next to
  16. eachother. 79 character wide lines leave just a spot for the cursor at the
  17. end of the line.
  18. * Control constructs like this:
  19. Good:
  20. if (condition)
  21. {
  22. }
  23. else
  24. {
  25. }
  26. for (init; condition; step)
  27. {
  28. }
  29. while (condition)
  30. {
  31. }
  32. /**
  33. * Documentation about behaviour
  34. * ...
  35. *
  36. * @param param1 the first argument
  37. * @param param2 the second argument
  38. */
  39. void function(param1, param2)
  40. {
  41. }
  42. class TheClass : public TheSubclass
  43. {
  44. };
  45. When there is only one statement you may leave out the braces, but don't
  46. place the statement on the same line as the condition:
  47. Good:
  48. if (condition)
  49. statement;
  50. Bad:
  51. if (condition) statement;
  52. * Includes:
  53. Source files should include their header first, to make sure the headers are
  54. self-contained. After that follow other project includes, grouped by
  55. directory and alphabetically ordered. System includes come last. All project
  56. includes are done relative from the 'src' directory.
  57. Good (subdirectory/source.cpp):
  58. #include "subdirectory/header.h"
  59. #include "somesub/bar.h"
  60. #include "somesub/zaro.h"
  61. #include <systemlib.h>
  62. * Comments:
  63. Single line C++ style comments are indented the same as the previous line.
  64. Good:
  65. // comment
  66. Multiple line C style comments are initially indented like previous line
  67. except every new line of the comment begins with a asterisk ('*') which lines
  68. up with the initial asterisk of the comment opening (1 space indent). The
  69. comment is closed also with the asterisk lining up. Comment text is only
  70. placed on a line starting with a asterisk.
  71. Good:
  72. /*
  73. * Some comment
  74. * additional comment material
  75. */
  76. Bad:
  77. /* text
  78. comment
  79. */
  80. Note that for documenting functions, methods and other things that can use
  81. documentation, you should use Doxygen style as in the function example above.
  82. For details see the manual at http://www.doxygen.org/.
  83. * Whitespace examples:
  84. Good:
  85. x = ((5 + 4) * 3) / 1.5;
  86. afunction(12, 3, (1 + 1));
  87. Bad:
  88. x = ( ( 5 + 4 ) * 3 ) / 1.5;
  89. afunction(12,3,(1+1));
  90. * Method, class, member and constant naming is based on the
  91. generally accepted way Java code is written.
  92. Class: CapitalizedWords
  93. Method: camelCase
  94. Member: mCamelCase
  95. Constant/enum: UPPERCASE_UNDERSCORES
  96. To denote global variables and functions the lowercase_underscores style may
  97. be used. Hungarian style should be avoided.
  98. * Whenever you add a new source file somewhere in ./src do not forget to add
  99. them in ./src/Makefile.am as well!