标签与空格缩进 [英] Tabs vs Space indentation

查看:199
本文介绍了标签与空格缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您阅读任何编码风格指南,您将有机会看到使用空格而不是标签缩进的建议。有些指南明确地说:从不使用制表符。

If you read any coding style guide, there is a big chance you will see a recommendation on using spaces instead of tabs for indentation. Some guides explicitly say: never use tabs.

我知道有可能发生关于制表符和空格的核战争。这肯定不是我打算。但我打算打算问你是否有任何好的理由这项建议。为什么大家都说空格是缩进代码的最好方法?

I know that there is a risk of starting a nuclear war about tabs vs spaces. It is surely not what I intend. What I do intend, however, is to ask you if there is any good reason for this recommendation. Why does everybody keep saying that spaces are the best way to indent code?

推荐答案

获取标签看起来正确取决于配置/所有软件的选择,源代码可能显示或打印。如果你有一套有限的这样的软件,发现这不是一个实际的问题,这是伟大的 - 去它如果你看到的价值。但是,请注意,当一个行缩进了制表符,然后继续在后面的行,你想要缩进基于开始括号的位置,排列引号等 - 你会混合制表符和空格的方式,在视觉上不可能验证的正确性(除非你的编辑器显示标签不同)。反对,使用箭头键交叉标签或删除,可以更快,但也更混乱和沮丧。对于使用不同标签宽度的不同人来说,在同一代码上干净地工作是很少见的,这也许是标签页的主要承诺。就个人而言,我使用空格。

Getting tabs to look right depends heavily on the configuration/choices of all the software the source code might be displayed or printed by. If you have a restricted set of such software and find that's not a practical problem for you, that's great - go for it if you see value. But, be aware that when a line is indented with tabs, then continued on subsequent lines where you want indentation based on the position of an opening parenthesis, to line up quotes etc. - you'll be mixing tabs and spaces in a way that's visually impossible to verify the correctness of (unless your editor shows tabs differently). Countering that, using arrow keys to cross tabs, or delete, can be faster but also more confusing and frustrating. It's rare for different people using different tab widths to work cleanly on the same code, which is perhaps the main promise of tabs. Personally, I use spaces.

这篇关于标签与空格缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆