STYLE.H 4.2 KB

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