StyleGuide.html 8.1 KB

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