logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

Shut-up-and-get-back-to-work-style.md (2632B)


  1. ---
  2. date: 2019-04-29
  3. layout: post
  4. title: The "shut up and get back to work" coding style guide
  5. tags: ["philosophy"]
  6. ---
  7. So you're starting a new website, and you open the first CSS file. What style do
  8. you use? Well, you hate indenting with spaces passionately. You know tabs are
  9. right because they're literally made for this, and they're only one byte, and
  10. these god damn spaces people with their bloody spacebars...
  11. Shut up and use spaces. That's how CSS is written[^1]. And you, mister web
  12. programmer, coming out of your shell and dipping your toes into the world of
  13. Real Programming, writing your first Golang program: use tabs, jerk. There's
  14. only one principle that matters in coding style: don't rock the boat. Just do
  15. whatever the most common thing is in the language you're working in. Write your
  16. commit messages the same way as everyone else, too. Then shut up and get back to
  17. work. This hill isn't worth dying on.
  18. If you're working on someone else's project, this goes double. Don't get snippy
  19. about their coding style. Just follow their style guide, and if there isn't one,
  20. just make your code look like the code around it. It's none of your goddamn
  21. business how they choose to style their code.
  22. Shut up and get back to work.
  23. Ranting aside, seriously - which style guide you use doesn't matter nearly as
  24. much as using one. Just pick the one which is most popular or which is already
  25. in use by your peers and roll with it.
  26. <div style="margin-bottom: 5rem"></div>
  27. ...though since I'm talking about style anyway, take a look at this:
  28. ```c
  29. struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
  30. double sx, double sy,
  31. double *sub_x, double *sub_y) {
  32. // Do stuff
  33. }
  34. ```
  35. There's a lot of stupid crap which ends up in style guides, but this is by far
  36. the worst. Look at all that wasted whitespace! There's no room to write your
  37. parameters on the right, and you end up with 3 lines where you could have two.
  38. And you have to mix spaces and tabs! God dammit! This is how you should do it:
  39. ```c
  40. struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
  41. double sx, double sy, double *sub_x, double *sub_y) {
  42. // Do stuff
  43. }
  44. ```
  45. Note the extra indent to distinguish the parameters from the body and the
  46. missing garish hellscape of whitespace. If you do this in your codebase, I'm not
  47. going to argue with you about it, but I am going to have to talk to my therapist
  48. about it.
  49. [^1]: For the record, tabs are objectively better. Does that mean I'm going to write my JavaScript with tabs? Hell no!