10 ms·
The only true answer to 'tabs vs. spaces'
- deleted 4y ago[deleted]
- 2bitencryption 4y agoI think there's another, equally-good answer: "I don't care, as long as it is consistent per codebase." I work on a codebase that my team owns, and we use spaces. I work on another codebase another team owns, and it uses tabs. I use whatever the codebase wants.
- jaywalk 4y agoYour answer isn't equally-good, it's worse. The argument for tabs is that each user can set them to display however they'd like. That's obviously not possible with spaces. So tabs make more sense.
- lesuorac 4y agoWhy isn't it possible with spaces? If an application is capable of rendering a tab as say N px of white space why can't it render 2 spaces as N px of white space?
- undersuit 4y agoBecause if someone sends me 8 space code and I'm normally 2 space code rendered as 4 spaces...
- lesuorac 4y agoAnd if they send you a 8 tab'd code and you normally only use 2 tab's then you'd have an issue as well.
- munch117 4y agoThen your editor renders the 8 space code as 4 spaces without missing a beat. Why wouldn't it? Detecting the indentation level used is trivial. (Provided, of course, that the author had the foresight to use spaces, not tabs.)
- undersuit 4y ago>Detecting the indentation level used is trivial. I agree that parsing a known correct file is trivial. Wouldn't a trivial thing be solved by now?
- munch117 4y agoWhenever I open a C file in Emacs, the indentation level is autodetected. I'll admit that may not have been trivial to implement, but it certainly has been done.
- chomp 4y agoIt is possible and there's IDE extensions for this at minimum for VSCode, it's just impossible to be consistent with tab indents, because you'll inevitably have to align with a space.
- lesuorac 4y ago> it's just impossible to be consistent with tab indents, because you'll inevitably have to align with a space. That's definitely application specific. I've seen other applications (not IDEs) use variable width tabs so that tabular data (Tables) would line up very well with only a single tab.
- deleted 4y ago[deleted]
- neltnerb 4y agoMore importantly, some people can only see maybe a dozen characters at a time due to vision impairment. To me, "can someone without good vision work with this code" was all the argument needed. Preferences, sure, accessibility though? Why not just make it simple? Rust also disappointed me on this, I just have never heard an argument for spaces that comes close to functional rather than just aesthetic. I don't honestly know why this is such a controversial topic.
- coldpie 4y agoWell I sure am glad we settled that.
- pupppet 4y agoBookmarking this story so I never forget this used to be a point of contention.
- linsomniac 4y agoAs someone who was a die-hard tabs guy for ~30 years, but has been using spaces for the last ~10: This post is correct, but irrelevant. I hung onto tabs for the reasons mentioned in the article: It doesn't require agreement on the number of spaces for an indent. I always liked 3 (a bit bigger indent than 2, not so much space as 4), but tabs meant people could pick whatever they liked. A single character that means "another indentation level" makes a lot of sense to me. But, at least in the Python world, spaces have won. So I switched, and whatever. I have bigger fish to fry, I'll use whatever. If I was on a team that chose tabs, I'd be fine with it. But I'd also be fine with spaces. Life is too short to care, tooling largely just takes care of it.
- hdjjhhvvhga 4y agoYeah, I'm surprised this is even still discussed. Most editors have a setting so I just adapt to what the code I work on is using and most often I don't even notice if it's spaces or tabs. I haven't seen anyone manually typing four spaces anyway. (At least not in the last decade or so.)
- throw0101a 4y ago> Life is too short to care, tooling largely just takes care of it. What's the point of even existing if you can't argue over minutia?
- blowski 4y agoShow me a single project where the decision either way has made any difference to the outcome. Stop wasting time discussing it.
- readthenotes1 4y agoIt's when the decision is "whatever I want" where the demons await...
- beached_whale 4y agoA lot of tools exist to autoformat code to a standard, or the language has one. Use the tools. In C++ we have clang-format, set it up and leave the decision to that. It just saves so much hasle and takes emphasis off of something that doesn’t matter by making it not matter.
- Gibbon1 4y agoBe nice to have a language that's designed to be formatted on the fly by the editor. Brings up my point, people need stop designing languages based on parsing raw text.
- beached_whale 4y agoThat doesn't really make sense in the world of people typing their programs. It is text.
- iamyemeth 4y agoI love that an article that can basically be summarized as: “tabs or spaces? - tabs” is on the front page of hacker news
- shadowgovt 4y agoThe true answer is "Whatever comes out the other side of your `format' command." And if you don't much care for what format outputs, configure your IDE to display it however you want it to.
- superb-owl 4y agoI was initially angry at the decision to use tabs instead of spaces in gofmt, but the advantages of having 95% of go projects use the exact same formatting has won me over. I'll happily give up my habits and preferences for more universal consistency.
- jameskilton 4y agoThere is one really good reason to always use tabs: accessibility. This comment is what sold me https://github.com/prettier/prettier/issues/7475#issuecomment-668544890 https://github.com/prettier/prettier/issues/7475#issuecommen...
- igetspam 4y agoThat comment wins. I have used spaces for decades and this is the most compelling reason I've seen to change that. Sold.
- scott-brd 4y agoYes! Not just braille, but eyesight problems in general. Someone using a 100pt+ font so they can see code really don’t want masses of screen estate used by spaces.
- CJefferson 4y agoI've seen this -- I'd be interested to know how many blind coders are using braille displays. I only know two blind coders, but both use standard accessible editors, using text-to-speech. They don't care about tabs vs spaces. I'm not sure which editors work well with braille displays (if any). They do care greatly about sticking 100% to an auto-code formatter, not for their benefit of reading other's codes, but so they didn't need to worry about accurate formatting themselves, which is another excellent reason to just pick a code formatter and use it on every commit religiously.
- whoomp12342 4y agoare you trying to start a civil war?
- wlindley 4y agoTabstops are still 9, 17, and every 8 thereafter... the standard on the VT-52 and VT-100 is still used when you 'cat' a file, and if you write files with tabs otherwise, you will have trouble with the console and the printer. Which is to say, I'm still fine with a tabs substituted for spaces wherever you like.
- cpcallen 4y agoI think the arguments in favour of tabs are pretty strong. But there are a couple of small issue: - You can't have aligned tables of data / blocks of comments / etc. if group of lines containing the aligned text have different amounts of indentation. - You can't place a fixed limit on line width (which many code formatting standards do, presumably to reduce horizontal scrolling and facilitate side-by-side diffs).
- sam_lowry_ 4y agoDouglas Crockford favours spaces in this great talk https://youtu.be/En8Ubs2k1O8 https://youtu.be/En8Ubs2k1O8
- slowmovintarget 4y agoDidn't Stephen McConnell settle this in the 90s in Code Complete? Spaces, no fewer than 2 and no more than 4, and follow the main convention of the language. Granted, you're hosed if you wrote C for the Linux kernel; you were stuck with 8.
- howeyc 4y agotabs vs spaces boils down to concern for others using tabs means everyone else can view the file with as many spaces as they want using spaces forces everyone else to view the file exactly as you see it