StyleGuide.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE html>
  2. <HTML lang=en>
  3. <HEAD>
  4. <style>
  5. body { background-color: #FFFFEE; font-size: 16px; font-family: Arial;
  6. color: #000000; margin: 0px;
  7. padding-left: 0px; padding-right: 0px;
  8. padding-top: 0px; padding-bottom: 0px; }
  9. H1 { padding-left: 10px; padding-top: 10px; padding-bottom: 10px; font-size: 26px; }
  10. H2 { padding-left: 10px; padding-top: 10px; font-size: 20px; }
  11. blockquote {
  12. color: #FFFFFF; background: #000000;
  13. font-size: 20px; font-family: monospace;
  14. padding-left: 5px; padding-right: 5px;
  15. padding-top: 5px; padding-bottom: 5px;
  16. }
  17. P { padding-left: 10px; }
  18. IMG { padding-left: 0px; padding-right: 0px;
  19. padding-top: 0px; padding-bottom: 0px; }
  20. A { font-size: 18px; font-family: Arial; color: #0000A0; text-decoration: none; }
  21. A:hover { color: #000070; background: #AAffAA; }
  22. A:active { color: #00A0A0; }
  23. .normal { font-size: 18px; color: #00A0A0; }
  24. .sub { font-size: 18px; color: #ffffdf; }
  25. </style>
  26. </HEAD>
  27. <BODY>
  28. <IMG SRC="Images/Title.png" alt="Logo titled DFPSR">
  29. <P>
  30. <A href="../Manual.html">Back to main page</A>
  31. </P>
  32. <h1>Code convention for David Forsgren Piuva's Software Renderer</h1>
  33. <P>
  34. To keep the style consistent, the style being used in the library is explained in this document.
  35. </P>
  36. <IMG SRC="Images/Border.png">
  37. <P>
  38. 1. Use common sense! If it looks wrong to human readers then it's wrong. Don't defeat the purpose of any rule by taking it too far.
  39. </P>
  40. <IMG SRC="Images/Border.png">
  41. <P>
  42. 2. Don't use iterators when there is any other way to accomplish the task. You can't write efficient algorithms without knowing the data structures.
  43. </P>
  44. <IMG SRC="Images/Border.png">
  45. <P>
  46. 3. Tabs for indentation then spaces for alignment. It's the best of both worlds by both having variable length tabs and correct alignment that works between lines of the same indentation.
  47. </P>
  48. <IMG SRC="Images/Border.png">
  49. <P>
  50. 4. No dangling else, use explicit {} for safety. Otherwise someone might add an extra statement and get random crashes.
  51. </P>
  52. <IMG SRC="Images/Border.png">
  53. <P>
  54. 5. No hpp extensions, use h for all headers. Could be either way, but this library uses *.h for compact naming, so keep it consistent.
  55. </P>
  56. <IMG SRC="Images/Border.png">
  57. <P>
  58. 6. C-style casting for raw data manipulation and C++-style for high-level classes.
  59. When using assembly intrinsics and raw pointer manipulation to alter the state of bits,
  60. verbose high-level abstractions only make it harder to count CPU cycles in your head.
  61. Always use the tool that makes sense for the problem you're trying to solve.
  62. C++ style is for things that are abstracted on a higher level.
  63. C style is for when a byte is just a byte and you just want to manipulate it in a specific way.
  64. </P>
  65. <IMG SRC="Images/Border.png">
  66. <P>
  67. 7. Don't call member methods with "this" set to nullptr.
  68. This would be undefined behaviour and may randomly crash.
  69. Use global functions instead. They allow checking pointers for null
  70. because they are explicit arguments declared by the programmer.
  71. </P>
  72. <IMG SRC="Images/Border.png">
  73. <P>
  74. 8. Avoid using STD/STL directly in SDK examples.
  75. Exposing types from the standard library should be done using an alias or wrapper in the dsr namespace.
  76. This allow replacing the standard library without breaking backward compatibility.
  77. The C++ standard libraries have broken backward compatibility before and it can happen again.
  78. </P>
  79. <IMG SRC="Images/Border.png">
  80. <P>
  81. 9. Don't abuse the auto keyword everywhere just to make it look more "modern".
  82. Explicit type safety is what makes compiled languages safer than scripting.
  83. </P>
  84. <IMG SRC="Images/Border.png">
  85. <P>
  86. 10. No new line for opening brackets.
  87. Makes the code more compact and decreases the risk of copy-paste errors.
  88. </P>
  89. <IMG SRC="Images/Border.png">
  90. <P>
  91. 11. Don't fix the style of someone else's code if you can easily read it.
  92. Especially if there's no style rule explicitly supporting the change.
  93. Otherwise style changes will defeat the purpose by introducing more version conflicts.
  94. </P>
  95. <IMG SRC="Images/Border.png">
  96. <P>
  97. 12. Don't change things that you don't know how to test.
  98. </P>
  99. <IMG SRC="Images/Border.png">
  100. </BODY>
  101. </HTML>