使用制表符而不是空格时保持最大线长度? [英] Maintaining Maximum Line Length When Using Tabs Instead of Spaces?

查看:267
本文介绍了使用制表符而不是空格时保持最大线长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各种语言的样式指南建议最大行长为80-100个字符,以便于阅读和理解。



我的问题是,如何使用制表符符合线路长度限制?因为,如果标签的长度在编辑器中设置为2,则在其他人的编辑器中,相同的代码可以超过 80个字符,标签长度设置为3/4/6/8。 / p>

有人建议我精神上看到我的标签长度​​为8个字符。这是不现实的,不会让我专注于编程,因为我必须检查它的每隔一行。



那么,你怎么样

解决方案

几乎所有的语言都有标签大小的约定。大多数项目都有标签大小的约定,通常(但不总是)与语言的标签大小相同。

例如,Ruby是2,Python& ; PHP是4,C是8等。



使用项目的标签长度​​,或者如果没有明显的项目标签大小,最常见的事情,因为这几乎所有的人会使用,除了几个。

设置不同的标签大小的能力可能是使用选项卡而不是空格的最大优点,如果一个用户希望偏离标准,那么很好,但是没有合理的方法来 在每种可能情况下都符合最大行长。



您可以将其与大多数网站进行比较;它们设计为100%缩放级别。放大或更改字体大小几乎总是有效,但有些小事情可能会中断。几乎不可能设计每一个可能的缩放级别&字体大小,因此接受人工制品。



如果您想确保代码符合 行长度使用空格,而不是真正的选项卡。就我个人而言,我觉得这些准则是:准则;而不是严格的规则,所以我认为这不重要。



就我个人而言,我喜欢制表符,因为很多原因现在不重要,但只有 >暂时偏离标准,通常在编辑重嵌套代码时,我想更清楚地说明我正在编辑的块。


Style guides for various languages recommend a maximum line length range of 80–100 characters for readability and comprehension.

My question is, how do people using tabs for indentation comply with the line length limits? Because, if the length of a tab is set to 2 in your editor, the same code could be over 80 characters long in someone else's editor with tab length set to 3/4/6/8.

Some suggest that I mentally see my tab length at 8 characters. This isn't realistic and won't let me focus on programming as I'd have to check it for every other line.

So, how do you (if you use only tabs in your code) do it?

解决方案

Almost all languages have a convention for tab size. Most projects have a convention for tabs size as well, which is usually (though not always) the same as the language's tab size.
For example, Ruby is 2, Python & PHP is 4, C is 8, etc.

Sticking with the project's tab length, or the language tab size if there is no obvious project tab size, is by far the most sane thing to do, since this what almost all people will use, except perhaps a few.
The ability to set a different tab size is probably the largest advantage of using tabs instead of spaces, and if a user wants to deviate from the standard, then that's fine, but there is no reasonable way to also comply with the maximum line length in every possible situation.

You can compare it to most web sites; they're designed for a 100% zoom level. Zooming in or changing the font size almost always works, but some minor things may break. It's practically impossible to design for every possible zoom level & font size, so artefacts are accepted.

If you want to make sure the code complies to both the line length and tab size, you should probably use spaces, and not "real" tabs. Personally, I feel these guidelines are exactly that: guidelines; and not strict rules, so I don't think it matters that much. Other people's opinion differs on this matter, though.

Personally, I like tabs, for a number of reasons which are not important now, but only deviate from the standard temporarily, usually when editing heavy-nested code where I would like some more clarity which block I'm editing.

这篇关于使用制表符而不是空格时保持最大线长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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