3 ms·
Indentation Indent 2 spaces. No tabs. Use blank lines between blocks to improve readability. Indentation is two spaces. Whatever you do, don't
by gman83 10y ago
Indentation
Indent 2 spaces. No tabs.
Use blank lines between blocks to improve readability.
Indentation is two spaces.
Whatever you do, don't use tabs.
For existing files, stay faithful to the existing indentation.
Richard Hendricks is not going to like that!
- andrepd 10y agoI don't wish to dig up a holy war, but why would you want to use spaces instead of tabs? That's what they're for, isn't it? One tab = one indentation level. No need for messing around with spaces, which serve other purposes.
- Sylos 10y agoThe usual argument is that a space is always the same width, whereas a tab can have varying widths depending on your editor. So, if you indent something with 4 spaces, then other people viewing your code will also always see 4 spaces, therefore ensuring that whatever you found to be readable indentation, does actually come out like that on the other end.
- Retr0spectrum 10y agoBut why does that matter? The reader can adjust their tab-width setting to whatever they prefer.
- scrollaway 10y agoSome people absolutely want indentation to be one specific size for everybody and don't fully understand that what might look readable for them at 2 space-widths, would be more readable for some others at 4 space-widths. Tabs are accessibility. People use spaces for the same misguided reasons they use px font sizes in css. (Rant over. Yeah, this annoys me.)
- roblabla 10y agoMy personal reason : Because it makes aligning stuff harder than it should be. I often have conditions that span multiple lines, and if they aren't aligned, it makes everything harder to read. By using spaces, I make sure the alignment is good for everybody. I'm sure there are other reasons too.
- Retr0spectrum 10y agoSee the third example on this page: https://blog.codinghorror.com/death-to-the-space-infidels/ https://blog.codinghorror.com/death-to-the-space-infidels/
- havetocharge 10y agoTabs get clobbered (turned into spaces) when you copy-paste them, especially between different environments. Spaces always get preserved.
- mwfunk 10y agoI would be happy with 100% tabs or 100% spaces, but in practice it seems like allowing tabs inevitably leads to source files indented with a combination of both, either by accident or because someone wants to have intermediate levels of indentation (for multiline conditionals for example). Once you have mixed tabs and spaces, everything goes to hell because now that code's formatting is tied to a specific person's idea of how many spaces should a tab display as, or whether tabs refer to tab stops or just a fixed number of spaces. I never had strong feelings about it until encountering some really pathological code bases, which had gotten to the point where there was literally no valid tab->spaces setting that would make everything look correct. Ultimately, though, these things really just don't matter. I use 4 spaces per indent level, but it's not like I'm incapable of reading and writing code that uses tabs, or 2 spaces, or 8 spaces. Really the only thing that matters is that there is a standard and that it is consistently applied within a project.
- etwigg 10y agohttps://github.com/diffplug/spotless https://github.com/diffplug/spotless
- lisivka 10y agoASCII defines tab as shift to next tab stop, at each 8 character. Terminals are following ASCII standard, so tab is too wide to use for indentation with fixed font at 80 characters.