TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Tabs or Spaces?

3 点作者 justWells超过 4 年前

9 条评论

oxinabox超过 4 年前
Semantically: tabs are simply correct. They encode actual meaning. Rather than merely presentation. They also win on accessibility, because someoen with visual difficulties can adjust their editor to display them as larger or smaller.<p>The counter to this is people using spaces for alignment, Like if one wants to list arguements below the openning backet of a function call, and line up the closing bracket.<p>The counter counter is: stop that. Adopt a style guide that doesn&#x27;t do alignment and sticks to a simple rule like &quot;Always indent once while within a multiline expression&quot; Alignment is for art. We don&#x27;t have time for your subjective view of what makes code pretty.
评论 #25826510 未加载
评论 #25826721 未加载
评论 #25826718 未加载
thesuperbigfrog超过 4 年前
There are more important things to worry about.<p>If you are working on a team, do what the team does.<p>If you are working alone, do whatever works best for you.
评论 #25826439 未加载
joshka超过 4 年前
There&#x27;s enough politics on hn right now, we don&#x27;t need to add religion to the mix ;)
评论 #25826486 未加载
Jemaclus超过 4 年前
Personally, I use tabs for indentation, spaces for alignment.<p>But more practically, I think the right thing to do is use an opinionated formatter (like Go&#x27;s gofmt or similar) and enforce that across the teams that you work with. Life&#x27;s too short to bicker about tabs vs spaces, when there are more important things to discuss like short variables vs long variables ;)
necovek超过 4 年前
In practice, I don&#x27;t care, and I lol-ed at the religion comment below.<p>And I know tabs are seeing a comeback lately, but they are basically the only ASCII character that does not have a predefined width.<p>And the reason I dislike that is because they don&#x27;t have clear semantics even in the pure text-only world: eg. writing out a table in ASCII is not possible with these &quot;tabulating&quot; characters, because if the column data is wider than (tab-width – 1), well, there goes your alignment. And when something is so badly <i>defined</i> not to serve the purpose it&#x27;s named after, I can&#x27;t like it. :)<p>If it was called the &quot;indent&quot; character which was ignored anywhere but at the start of the line, it would at least be sane and consistent.<p>Incidentally, Emacs can do the right thing in most modes by turning tab <i>key</i> into the (re)indent command.
TheAnswerMan超过 4 年前
Both. Tabs up to the current level of indentation. Then spaces after that for alignment. Spaces never come before a tab, only after and only for alignment purposes.<p>Everyone likes to take a dump on mixing tabs&#x2F;spaces. But it solves all problems with both. Everyone can view the indentation width they prefer; 2, 3, 4, 8, whatever. And alignment is always correct no matter what width you prefer. An auto format tool can remove the need to manually deal with anything.<p>Indent width is a visual effect that should not be mandated. You wouldn&#x27;t mandate a color scheme for your code base, so why would you mandate indentation width?
jolmg超过 4 年前
From the guidelines:<p>&gt; Eschew flamebait. Don&#x27;t introduce flamewar topics unless you have something genuinely new to say. Avoid unrelated controversies and generic tangents.
uberman超过 4 年前
This is why every project should have a <i>.editorconfig</i> associated with it.<p><a href="https:&#x2F;&#x2F;editorconfig.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;editorconfig.org&#x2F;</a>
jjgreen超过 4 年前
both!<p><a href="https:&#x2F;&#x2F;dev.to&#x2F;__shadz_&#x2F;tabs-vs-space-49l5" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;__shadz_&#x2F;tabs-vs-space-49l5</a>