TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Who decided indenting with spaces was a good idea?

8 pointsby stevekinneyabout 10 years ago

9 comments

nostrademonsabout 10 years ago
It&#x27;s because at some point, your code <i>will</i> encounter low-tech technology that doesn&#x27;t let you set the tabstop. This might be a terminal app, or an actual dumb terminal, or a cut &amp; paste into a textbox on a webpage, or a third-party tool that expects spaces only, or a refactoring tool that you wrote yourself but don&#x27;t have time to get working with tabs, or a parser that can count characters but has no logic for tabs. When this happens, your tab-based formatting will get messed up, while your spaces-based formatting will look exactly the way you wrote it.<p>A lot of mysteries about why people don&#x27;t use clearly-superior technological solutions are solved by understanding that ubiquity is a feature, in many cases the most important feature. I don&#x27;t use vim because it&#x27;s the best text editor; I use it because I can be reasonably sure every single UNIX-like system I ever log into will have it, and once it&#x27;s in my fingers from having to learn it on a remote server, I might as well use it for daily programming. I don&#x27;t use HTTP because it&#x27;s an efficient protocol; I use it because every single device, library, and language speaks it. I didn&#x27;t write Gumbo [1] in C because I like the language; I did it because every modern language can bind to C libraries, and so this lets a maximum number of people use it.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;gumbo-parser" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;gumbo-parser</a>
评论 #9311012 未加载
评论 #9310459 未加载
smt88about 10 years ago
Oh god. You might as well have posted, &quot;Why do people use Mac instead of Windows?&quot; in the year 2002.<p>People use spaces <i>because</i> they&#x27;re a fixed width, not in spite of that fact. They allow you to know that your code will look exactly the same with any monospace font, which is especially important if you do things like lining up operators.<p>I personally use a hybrid: the entire line is indented with tabs. This tells you which block you&#x27;re in.<p>Then, for alignment or anything else that isn&#x27;t related to the entire block, I use spaces.<p>Many IDEs support this hybrid mode, including the IntelliJ family. It gives you the best of both worlds.
评论 #9308421 未加载
UnoriginalGuyabout 10 years ago
&gt; tabs actually use less space on disk as only one character is stored instead of 2, 4 or 8.<p>If I didn&#x27;t have the ability to store 1,000,000,000,000 of them, I&#x27;d care greatly. To be honest source code size isn&#x27;t even in the ballpark of concerns I have. Intermediate bin files (e.g. obj files) are far larger and problematic for source control and sending source to someone (e.g. several meg a piece rather than a couple of hundred KB).<p>As for an answer to your question: Spaces are an exact width. Tabs change widths. Therefore for precision and reproducibility spaces are a better choice across all platforms.<p>Many IDEs support inserting a preset number of spaces when you tab anyway, so the problem is invisible to you.
评论 #9313658 未加载
jannottiabout 10 years ago
Because sometimes you <i>must</i> use spaces, because you are indenting a continuation line that should be indented to an exact spot with respect to the previous line (you&#x27;re in the middle of an expression, you want to be at the start of an open parenthesis, etc).<p>Surely the suggestion in that case is not to carefully insert tab characters to the same indentation of the previous line, and then spaces for the rest, so that you have some tabs and some spaces on the continued line? Anything else fails if the tabs are set as &quot;developer preference&quot; on display, but that tabs + spaces on one line is incredibly fiddly.
评论 #9310391 未加载
评论 #9308501 未加载
mblakeleabout 10 years ago
<a href="http:&#x2F;&#x2F;www.jwz.org&#x2F;doc&#x2F;tabs-vs-spaces.html" rel="nofollow">http:&#x2F;&#x2F;www.jwz.org&#x2F;doc&#x2F;tabs-vs-spaces.html</a>
daeminabout 10 years ago
Even though I prefer to use tab characters at home it would be much better if a single tab character could indent the code to the appropriate level. So a tab character means indent the code to where appropriate based on some predefined rules. Granted this is only possible for some languages and not others, and it would be much nicer even when using a non-flat file for code.
facorreiaabout 10 years ago
The guy that had to use punched cards to enter code that would be printed to paper.<p><a href="http:&#x2F;&#x2F;computers.mcbx.netne.net&#x2F;media&#x2F;pcards&#x2F;k_cobol_cyf.jpg" rel="nofollow">http:&#x2F;&#x2F;computers.mcbx.netne.net&#x2F;media&#x2F;pcards&#x2F;k_cobol_cyf.jpg</a>
irascibleabout 10 years ago
TABS + 1TBS = Pabst Blue Ribbon MF!
a3voicesabout 10 years ago
Because you can move the cursor vertically and be in the correct column.
评论 #9308512 未加载