STYLE.H 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. STYLE GUIDE FOR COMMAND & CONQUER : TIBERIAN SUN
  20. In addition to the standard Westwood programmer's style guide, the following
  21. guidelines apply.
  22. > Use every feature the compiler has that will help catch bugs and encourage
  23. solid portable coding practices. i.e., turn on all warnings and treat all warnings
  24. as errors. Use helper programs such as Lint, BoundsChecker, or CodeGuard whenever
  25. possible.
  26. > Keep related items together. Examples: Declare variables right before they are
  27. used. Keep functions that work on the same subsystem, within the same module.
  28. > Use consistent commenting and spacing style. Examples: see existing Red Alert
  29. code. Creative freedom does not extend to formatting.
  30. > Use descriptive variable names. Examples: Use "index" rather than "i". Use
  31. "unit_index" rather than "index".
  32. > Use a consistent variable and function naming convention. Examples; boolean
  33. variables should begin with "Is" (e.g., "IsActive", "IsFiring"). Functions that
  34. exist solely to return a similar boolean query should begin with "Is_".
  35. > If you have a variable that only serves a boolean function, then declare it
  36. as "bool" rather than as "int" and assign it "true" or "false" rather than "1"
  37. or "0".
  38. > Choose function and variable names that are precise, descriptive, and concise (in that
  39. order).
  40. > Hide data where possible: Examples: If a global is only used in one module, make
  41. it static to that module. If a helper function is only used in one module, make it
  42. static as well. Hide class members in the private section if they aren't needed
  43. public. Most variables aren't needed as public.
  44. > Keep function bodies short. It is often times, more easy to understand and maintain
  45. if a very long function is broken up into helper functions with descriptive names.
  46. A clue if a function is too long is if you can page down 5 times and still be somewhere
  47. in the middle of the function. If you can page down 10 times and still be in the
  48. function, you've got a serious function size problem.
  49. > Compare pointers to NULL and integer types to zero (NULL) instead of using the
  50. "if (x)" or "if (!x)" format. This short format should only be used for boolean
  51. values and expressions. It is just as efficient and it makes it more clear to the
  52. reader that the variable is a pointer and not a simple boolean value.
  53. > Use "const" when declaring any member functions that do not modify data. Corollary --
  54. make sure any function that appears like it will not modify data will, in fact, NOT
  55. modify any data. Example; A function called Is_Able_To_Move() shouldn't modify the
  56. object nor should it actually cause something to start moving! The use of "const" is a
  57. variation on style guide rule #1 (use the compiler to help ensure proper code).
  58. > Shun using assembly language except in extreme cases. Such would be if a
  59. function can only be performed by using assembly (requires special opcodes), or
  60. if performance would be PROVEABLY dramatically improved. Don't code in assembly for
  61. performance reasons if there isn't benchmarking code in place to analyze the results.
  62. As a corollary, design a better algorithm as the first recourse.
  63. > Keep class interfaces small and simple.
  64. > Organize algorithms to use as few special case "if" statements as possible. Data
  65. tables or data files are preferred. This follows the generally good guideline of offloading
  66. as much processing as possible to compile-time rather than run-time.
  67. */