为什么我们在 IDE 中使用固定宽度字体?

发布于 2024-09-06 20:19:52 字数 219 浏览 3 评论 0原文

可能的重复:
为什么在 IDE 中使用等宽字体?

几乎所有程序员(和代码编辑器)使用固定宽度字体。这是为什么呢?

Possible Duplicate:
Why use monospace fonts in your IDE?

Virtually all coders (and code editors) use fixed width fonts. Why is this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

茶色山野 2024-09-13 20:19:53

拼写错误/缺失字母可以看得更清楚

typos/missing letters can be seen clearer

黄昏下泛黄的笔记 2024-09-13 20:19:53

这是一个选择的问题。我个人更喜欢使用非常优雅的 Comic Sans 或 Purisa 字体进行编程。

It's a matter of choice. I personally prefer to use the very elegant Comic Sans or Purisa font for programming.

戒ㄋ 2024-09-13 20:19:53

在您最喜欢的编辑器中打开一些代码...我假设默认情况下您的文本编辑器将具有固定宽度的字体集。

现在将字体更改为 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.

残花月 2024-09-13 20:19:53

主要是为了提纲。不过,这也是一种习惯。我来自老式 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.

嗳卜坏 2024-09-13 20:19:52

可能是因为它使代码更容易扫描 - 你有代码“块”,即。垂直排列的文本比普通散文中的文本要频繁得多。如果字体不是固定宽度,则视觉上不会对齐。

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.

年少掌心 2024-09-13 20:19:52

它极大地增强了可读性 - 特别是标点符号,它们在代码中起着非常重要的作用,并且可变宽度字体经常“挤压”到最小的空间。

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.

我是有多爱你 2024-09-13 20:19:52

只需尝试非固定宽度的字体即可。

Just try a non fixed-width font.

鲜血染红嫁衣 2024-09-13 20:19:52

因为它有助于代码布局,并且更容易发现错误,因为对于给定数量的字符,行的长度是一致的。

这也是历史性的,因为我们曾经使用具有固定宽度字体的终端。

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.

渔村楼浪 2024-09-13 20:19:52

我知道我迟到了一周,但我不敢相信没有提到像 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.

黄昏下泛黄的笔记 2024-09-13 20:19:52

我想添加一些次要原因,主要与代码的视觉流程相关:

  • 您可以对齐变量赋值(或不对齐)
  • 一个典型的示例是对齐表声明,以便它看起来像代码中的表。

    var sn = [ 8349824, 3094230, 1]; // 表格第一行
    var 长名称1 = [ 421, 1324, 5382920]; // 第二个表格行
    // 尝试做一些以可变宽度字体可读的事情!
    
  • 您可以就具有一致效果的线宽限制达成一致。

  • 您的代码在任何地方都有相同的“面孔” - 无论您是在网络上的 块中、在远程终端上的基本文本编辑器中还是在具有抗锯齿字体的图形 IDE 中读取它 -您将立即认出该代码。
  • 导航代码时的行为更可预测 - 当我向上或向下移动时,我已经确切地知道光标将在哪里结束。

简而言之,固定宽度字体允许对源代码外观和可读性进行更细粒度的控制,独立于任何给定字体的可用性。

I would add a few minor reasons, mainly related to the code's visual flow:

  • You can align variable assignments (or not)
  • One typical example would be aligning table declarations so that it will look like a table in the code.

    var sn        = [ 8349824, 3094230,       1]; // first table line
    var longname1 = [     421,    1324, 5382920]; // second table line
    // Try and do something as readable in variable width font!
    
  • You can agree on a line-width limit that will have a consistent effect.

  • Your code has the same "face" everywhere - whether you read it in a <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.
  • More predictable behaviour when navigating code - when I go up or down, I already know exactly where the cursor will end up.

In short, fixed-width font allows for finer grained control over source code appearance and readability, independant from the availability of any given font.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文