5 ms·
Ask HN: Tabs or Spaces?
Tabs or Spaces?
- yellowsir 10y agotabs, don't you watch sillicon valley?
- zerr 10y agoHere is the compromise: one tab in between two spaces.
- deleted 10y ago[deleted]
- wrong_variable 10y agospaces ( I know I am a monster, stop staring at me ! )
- marksamman 10y agoTabs for indentation, spaces for alignment.
- nilved 10y agoI agree with this to the extent that I will say it's the sensical answer. I think that tabs are an obvious choice because they are semantic intendation rather than generic spacing. For this reason the front-end can render them with 2, 4, 8 or whatever amount of spaces, without requiring the code be changed.
- NKCSS 10y agoVisual Studio automatically converts tabs to spaces (default setting; can be changed). Personal preference; 2 indent (spaces) instead of full 4.
- jdhzzz 10y agoSeconded. Ultra edit does the same tab->space conversion.
- koolba 10y agoWhatever the file already has. If it's empty, spaces.
- doc_holliday 10y agoSpaces of course. Tabs can be messy across version control and multiple users with differing OS / editor.
- doc_holliday 10y agoAnd to add... there is no excuse not to use spaces even if you like the tab key. Configuring your favourite text editor to interpret a tab key press as 2, 4 or whatever number of spaces for your project is trivial.
- deleted 10y ago[deleted]
- king_magic 10y agoSpaces.
- pvinis 10y agoMany people use tabs in the beginning of the line, and spaces for anything after any visible character in the line. If people choose a different way, is because they have a reason, or they don't care. If you're not sure, use whatever the file already uses, or the way I described above, or whatever makes you feel fuzzy inside. In that order!
- lucasnemeth 10y agospaces, tabs are nonsense
- takatin 10y agoTabs. There's a reason we put tab key on every keyboard out there, it is built specifically for alignment The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form." When a person wanted to type a table (of numbers or text) on a typewriter, there was a lot of time-consuming and repetitive use of the space bar and backspace key. — https://en.m.wikipedia.org/wiki/Tab_key
- bobisme 10y agoTab is great for auto-complete.
- lumberjack 10y ago>There's a reason we put tab key on every keyboard out there To insert 4 consecutive spaces at once.
- VMG 10y agoWhat the purpose of the backspace key?
- verytrivial 10y agoYes. Just not both.
- insin 10y agoSpaces for indentation, spaces for alignment... ...but using the tab key /glares at Silicon Valley/
- ancarda 10y agoI think she did that just to see if he would get annoyed.
- olouv 10y agoSpaces! https://github.com/airbnb/javascript#whitespace--spaces https://github.com/airbnb/javascript#whitespace--spaces
- deleted 10y ago[deleted]
- satysin 10y agoSomebody watched Silicon Valley last night :) And I go with whatever the current file is. If I didn't make the file I respect the style of whoever did. For my own files I prefer spaces.
- RaycatRakittra 10y agoFor a very long time, I thought tabs were the way to go. It provided the most compatible coding style between my languages (Lua, C, Assembly, etc.) The only sticking point was JavaScript, which used spaces. But now that I develop across devices, I'd have to say spaces simply because of encoding issues re: Unicode. Sure, you could ensure your encoding type, but that's an extra step you shouldn't have to do.
- datalist 10y agoCan you elaborate on what problems you encountered with tabs in a Unicode context?
- wcummings 10y ago(setq indent-tabs-mode nil)
- ebbv 10y agoTabs. Spaces are how you end up with one class where one method is 2 space indent and another is 4 and another is 12 because your team all has different preferences (and two of them are insane.) Tabs means everyone can use whatever preference they want and not be bothered by anyone else's preference.
- maze-le 10y agoSince my first contact with Python: spaces!
- louis-paul 10y agoTabs. Spaces for indentation are an heresy. To go further, always use a standard formatting tool (gofmt, clang-format...) before committing code.
- bryanlarsen 10y agoI wish the answer was elastic-tabstops http://nickgravgaard.com/elastic-tabstops/ http://nickgravgaard.com/elastic-tabstops/ But compatibility trumps awesomeness, so spaces.
- citrusx 10y agoSpaces. The variability in the ways tabs are displayed, which you can not control, make tabs a non-starter. Spaces always look like spaces. So when you use them, your text looks the same wherever it is displayed, and that requires no additional work. The one caveat here (if you don't already know) is that the `make` utility has never been updated to allow spaces, even to this day. So, you must use hard tabs in Makefiles. Also worth knowing is that Python's official style guide, PEP-8, insists on spaces (specifically, 4 spaces), and the officially-provided formatting tool for Go uses tabs (a decision that I was most displeased with). It's physically possible to go against these recommendations, but you're not likely to find any community cooperation for that decision if you're working in those two languages.
- WayneBro 10y ago> The variability in the ways tabs are displayed, which you can not control, make tabs a non-starter. You can absolutely control the way tabs are displayed. Using a poorly built tool that doesn't give you that option is the non-starter. The rest of what you said are just random facts that don't really support your preference.
- deleted 10y ago[deleted]
- datalist 10y agoI second what WayneBro wrote.
- datalist 10y agoA downvote for agreeing with someone, seriously?
- bryanlarsen 10y agoI didn't downvote you, but your comment doesn't add anything to the public conversation, it just clutters it. Just click the upvote button next time.
- 10y ago
- rajington 10y agoi write pre-minified js, all in one line.
- ddri 10y agothisonemademelaughoutloud
- kavehmz 10y agoNeither, Go or Python, so I don't spend time on this trivial decision anymore.
- poops 10y agoI prefer tabs because it doesn't force all devs to have the same level of indentation.
- datalist 10y agoTabs. I used to prefer spaces until I came across an argument which convinced me to convert: Indentation can be something very subjective, some prefer two spaces, others four and yet again others maybe eight. With spaces everyone is forced to use one particular style. With tabs everybody can configure it exactly the way they want and it will be displayed in one unified style.
- deleted 10y ago[deleted]
- stasm 10y agoThe problem with this customization is that different styles end up with different allowed character counts in a single line. For linters to work as expected you still have to hardcode the number of spaces a tab should count as in the linter's config. At which point you could just use spaces and treat indentation as part of the content—not presentation.
- codewritinfool 10y agoTabs. I like controlling the level of indentation I see.
- joewood1972 10y agoThe best answer is to use a tool that saves in the format that the file was in originally. I think VSCode and some others do that. If the file only has 2-space indentation then TAB becomes 2-spaces. etc... That said, assuming a greenfield the best case has to be to use tabs. This way if somebody has a preference to small indents then they can configure the TAB to render as 2-spaces - it becomes a render issue. So, use a modern tool and it's a moot point. P.S. not sure why Silicon Valley's Richard started talking about 8 space tabs. That would be crazy. The only time I've seen that is in a proportional font in a word processor.
- gumballhead 10y agoGitHub renders tabs as 8 spaces. It is crazy and looks ridiculous.
- jon-v 10y agoThis is actually the only truly rational defense I can come up with for my preference of spaces vs tabs. (The generic argument is that the code will look the way I want it to even when rendered by a tool where I can't control the tab width, but Github is the only real example these days.)
- Nejohnson88 10y agoTabs all the way man it so much easier for code control.
- egwynn 10y agoIdeally tabs. That's what they're for. But at some point someone on your team who doesn't understand the difference is gonna start making changes and screw it all up. Because of this, I use spaces. That way it always looks the way I intend it to look no matter how poorly the viewer's text editor is configured.
- datalist 10y agoMixing styles will always lead to a mess though, regardless of whether one uses tabs and then someone "introduces" spaces or vice versa. Using spaces wont help much in that case.
- gregjor 10y agoTabs, but this shouldn't be an issue for programmers using a real editor, something more sophisticated then Notepad. Vim can convert between tabs and spaces easily, and almost every modern editor I've used can do the same. Using spaces to force everyone to your preferred indentation is like forcing the font size. I can't read code indented two spaces, but if we use tabs I can set the indent to 4 spaces widths and someone with younger eyes can use 2.
- joesmo 10y agoI don't care and I only want to work with engineers who also don't care and would rather spend their brainpower on actual problems, not bikeshedding.
- jibsen 10y agoMost importantly, whatever the language or codebase you are working in/on mandates. I write a lot of C, and given the choice, I tend to prefer tabs for indentation and spaces for alignment. I use a tab-width of 8, so the code will look fine for anyone using a lower tab-width. Converting from tabs to spaces is a simple search-and-replace, whereas the other way is more work (there was an article here recently about algorithms to guess indentation width).
- zastrowm 10y agoSpaces. A single character shouldn't expand to look like multiple characters.
- rmurri 10y agoMixing tabs and spaces is the worst. I'm surprised none of the commenters has mentioned line continuations, which tabs suck at. Since I can't mix and match I prefer spaces.
- drinchev 10y agoIt doesn't matter. Just choose tabs or spaces per project and be consistent. If you join a project already using tabs / spaces and you wanna switch, don't bother doing that.
- aibotter 10y agoSpaces over Tabs, Vim over Emacs! #TeamNoSexForRichard
- strollup 10y agoHey Richard. What? Space.Space.Space.Space.Space.Space Worst than middle finger :D