为什么我们在 IDE 中使用固定宽度字体?
可能的重复:
为什么在 IDE 中使用等宽字体?
几乎所有程序员(和代码编辑器)使用固定宽度字体。这是为什么呢?
Possible Duplicate:
Why use monospace fonts in your IDE?
Virtually all coders (and code editors) use fixed width fonts. Why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
拼写错误/缺失字母可以看得更清楚
typos/missing letters can be seen clearer
这是一个选择的问题。我个人更喜欢使用非常优雅的 Comic Sans 或 Purisa 字体进行编程。
It's a matter of choice. I personally prefer to use the very elegant Comic Sans or Purisa font for programming.
在您最喜欢的编辑器中打开一些代码...我假设默认情况下您的文本编辑器将具有固定宽度的字体集。
现在将字体更改为 Comic-Sans...说得够多了!
但说真的,固定宽度阅读起来要清晰得多。
open some code in your favourite editor... I'm presuming by default that your text editor will have a fixed-width font set.
Now change the font to Comic-Sans..... enough said!
Seriously though, fixed-width is much much clearer to read.
主要是为了提纲。不过,这也是一种习惯。我来自老式 IDE,当时它们还处于 MS-DOS 中。
此外,像微软这样的公司也制作了字体,以使其“更容易”编码。在 Visual Studio 中编码时,我自己更喜欢 Consolas 字体。
格兹,克里斯。
Mostly for outlining. However it's also a habit. I come from the old school IDE's while they were still in MS-DOS.
Also companies like Microsoft have made fonts to make it "easier" to code with. I prefer the Consolas font myself while coding in Visual Studio.
Grz, Kris.
可能是因为它使代码更容易扫描 - 你有代码“块”,即。垂直排列的文本比普通散文中的文本要频繁得多。如果字体不是固定宽度,则视觉上不会对齐。
Probably because it makes the code easier to scan - you have "blocks" of code, ie. text that lines up vertically far more often than you would in normal prose. If the font is not fixed width than it wouldn't be visually aligned.
它极大地增强了可读性 - 特别是标点符号,它们在代码中起着非常重要的作用,并且可变宽度字体经常“挤压”到最小的空间。
It greatly enhances readability - expecially of punctuation characters which have a very important role in code and which variable width fonts often "squeeze" into minimal space.
只需尝试非固定宽度的字体即可。
Just try a non fixed-width font.
因为它有助于代码布局,并且更容易发现错误,因为对于给定数量的字符,行的长度是一致的。
这也是历史性的,因为我们曾经使用具有固定宽度字体的终端。
Because it helps with code layout and make it easier to spot errors as lines are a consistent length for a given number of characters.
It is also historical as we used to use terminals with fixed width fonts.
我知道我迟到了一周,但我不敢相信没有提到像 FORTRAN 这样基本上需要固定宽度字体的编程语言。注释字符必须放在第 1 列中,行延续字符必须放在第 6 列中,这甚至没有提到打孔卡固有的固定宽度字体效果。有人提到过终端上的固定宽度字体,但编程甚至早于这。
I know I am a week late to the game but I can't believe that there is no mention of programming languages like FORTRAN that basically required fixed width fonts. Comment chars had to go in column 1, line continuation chars in column 6 and that is not even mentioning the inherent fixed width font effect of punch cards. Mention has been made of fixed width fonts on terminals, but programming predates even that.
我想添加一些次要原因,主要与代码的视觉流程相关:
一个典型的示例是对齐表声明,以便它看起来像代码中的表。
您可以就具有一致效果的线宽限制达成一致。
块中、在远程终端上的基本文本编辑器中还是在具有抗锯齿字体的图形 IDE 中读取它 -您将立即认出该代码。
简而言之,固定宽度字体允许对源代码外观和可读性进行更细粒度的控制,独立于任何给定字体的可用性。
I would add a few minor reasons, mainly related to the code's visual flow:
One typical example would be aligning table declarations so that it will look like a table in the code.
You can agree on a line-width limit that will have a consistent effect.
<code>
block on the web, in your basic text editor on a remote terminal or in your graphical IDE with antialiased fonts - you will immediately recognize the code.In short, fixed-width font allows for finer grained control over source code appearance and readability, independant from the availability of any given font.