StyleGuide.html 6.6 KB

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