It should go without saying that, for existing projects, you should just use the established convention. The only thing worse than 3 spaces of indentation is x spaces of indentation, where x is a arbritrary unsigned intiger that can change depending on which file you are looking at.

Though in the above comparison, spaces had more points than tabs, spaces also had more points refuting itself. In sum, tabs are better. For indentation, the width is about as important as the editor font or theme. Tabs are therefore more suited for indentation (as they tend to come with a customiseable width). As for alignment, use spaces, not tabs4.

Some people like an indent width of 2, others 4, some 8 or 6 or even 3- cut the crap, use a tab; let users decide how many spaces that tab represents.

If you can, use an auto formatter! I can write the most horifically wrong code in the world and rustfmt will clean it up for me.5

Further reading

This excellent reddit thread has some nice thoughts on the benefits of spaces, including a back-and-forth between pro-space and pro-tab people.

  1. I’ve heard that github actually added a user setting for this, as has gitlab. Gitea unfortunately does not have a user setting for this, however it does support a per-repo .editorconfig file ↩︎

  2. I say some, really i just mean rustfmt. Python also recommends spaces, but that’s just a recommendation. Apparently Ruby has a strong convention of 2 spaces.↩︎

  3. Google comes to mind. I can’t be bothered to visit any of their websites though, so you’ll just have to trust me when I say I remember it being 2 spaces of indent↩︎

  4. this is default behaviour for rustfmt↩︎

  5. worth noting that rustfmt defaults to 4 spaces of indent, but will allow me to set per-user and per-project overrides; no more arguments about formatting, if rustfmt likes it i like it!↩︎