47 comments

[ 3.7 ms ] story [ 96.6 ms ] thread
I hope not.
Why not? There are enough people that use Vim to just write prose. You don’t need monospaced fonts then.
I also program in non-monospaced fonts. There is no reason not to.
No reason at all? Not saying you're wrong per se, but basically you're saying all the monospaced fonts out there used by default in a ton of code editors are there for no reason. Or at least not a good one. Can you elaborate?
Many programmers believe that it is impossible, or at least impractical, to code effectively in a monospaced font.

For most kinds of code, this is a mistaken belief.

You only need a monospaced font if you want to use column alignment. But it's really quite rare that column alignment is necessary. It can almost always be replaced with simple indentation.

Here's what I mean by column alignment:

  function foo(firstArgument,
               secondArgumentFunctionCall(itsArgument,
                                          itsOtherArgument),
               thirdArgument) {
      bar();
  }
Obviously, those arguments won't line up in a proportional font. But this kind of column alignment is a bad practice anyway. It leads to excessive line lengths, spurious VCS diffs, and is just generally fiddly.

The Rust/Servo coding guidelines formerly mandated column alignment like this. But after seeing the problems it caused in their codebase, they switched to a pure indentation style like the one I've used for many years.

The idea is simple. Stop making a distinction between statements and expressions, and instead format expressions just as you would format blocks of statements:

  function foo(
      firstArgument,
      secondArgumentFunctionCall(
          itsArgument,
          itsOtherArgument
      ),
      thirdArgument
  ) {
      bar();
  }
Once you start using this kind of format, it no longer matters whether you use a monospaced or proportional font. It doesn't even matter whether you use tabs or spaces! The notion of "tabs for indentation, spaces for alignment" goes away when you don't use alignment.

I think every programmer should try using proportional fonts for a while. Even if you decide you prefer monospaced after all, it's an educational experience to see that monospaced fonts are just not necessary for most programming, and that tabs work fine once you stop using alignment.

> Many programmers believe that it is impossible, or at least impractical, to code effectively in a monospaced font.

Your post was the very first place I've ever saw that assertion in any shape or form. I never heard anyone come close to make that assertion ever.

Moreover, modern IDEs started featuring functionalities that rely on monospace fonts, such as selecting blocks of text by both rows and columns.

You should pass off your personal opinion as your own personal opinion instead of posting baseless assertions wrapped in an unbelievable appeal to popularity.

  > > Many programmers believe that it is impossible, or at least
  > > impractical, to code effectively in a monospaced font.
  >
  > Your post was the very first place I've ever saw that assertion in
  > any shape or form. I never heard anyone come close to make that
  > assertion ever.
That's almost certainly a typo, and the GP almost certainly meant to say "without a monospace font" or "in a proportional font".

In fact, 2 sentences later he/she says "You only need a monospaced font if you want to use column alignment." This is presumably meant to contradict the assertion in the first sentence.

I'm sorry, I meant to get back to you a week ago.

As pmoriarty pointed out, that was indeed a typo, and a rather embarrassing one!

The funny thing was that as I was writing that sentence, I first wrote:

"The vast majority of programmers believe..."

And then I decided to tone down the language a bit. But my initial wording would have made the typo fairly obvious. So it goes. :-)

> functionalities that rely on monospace fonts, such as selecting blocks of text by both rows and columns.

I use that "column selection" mode with proportional fonts too. It works fine, even though the selected block has ragged right edges.

VCS diffs are broken by design (in a sense of this subthread). Remove a single “if” around a block of code, reindent it, and now you got all lines changed. I wish VCS had special modes for source code that would compare lextoken-wise and show only what actually changed, leaving formatting to personal tastes. Yeah, no more style wars: tab/space, space/newline/none, trailing comma – all become irrelevant. Sigh.

Edit: a worst nightmare is a diff that removed “if” and also fixed a mistype in one of 20 reindented lines.

You can do "ignore spaces" in your diff of choice to fix this shortcoming.
Omg. Thanks for pointing that out, I can’t believe that I missed this option in svn manual for so many years. Such a shame...
You only need a monospaced font if you want to use column alignment. But it's really quite rare that column alignment is necessary. It can almost always be replaced with simple indentation.

I suspect that most programmers have tried a proportional font for coding and found it unpleasant.

Do you really think so? My experience has been that most developers who see me using proportional fonts are surprised that it's even possible to work productively with them. I haven't run into anyone who said, "Oh yeah, I tried proportional fonts too but I didn't like them."
> but basically you're saying all the monospaced fonts out there used by default in a ton of code editors are there for no reason.

That assertion only makes sense if you assume that indentation or even indentation style have no relevance in software development, and thus there is no reason to consider those basic requirements in any activity related to coding.

(comment deleted)
Was curious what language(s) you regularly program in, and if you generally develop/maintain solo or as part of a team?

I don't agree with your disposition, but I don't think it's necessarily wrong either...perhaps subjectively driven based on your "norm" vs. what others have experienced, e.g. I ocassionally program in a niche language where the first 7 columns are strictly defined by BNF, uses relatively heavy ASCII art commenting by local coding convention, and will throw obscure errors if a character on any line exceeds the 80th.

>There is no reason not to

If you've reached that conclusion, I suspect I would not enjoy reading your code very much.

>There are enough people that use Vim to just write prose.

One of vim's main features is enabling users to navigate by row/vertically while traversing the same column. If someone uses non-monospace fonts then columns won't be aligned and that sort of move makes traversing text an illogical and unintelligible endeavour.

Thus defeating the whole point of using vim.

I thought the whole point of using vim was having access to powerful, mnemonics and highly composable commands to edit text efficiently… Guess I was wrong.
Composable, yes, as in compose movements with commands.

The thing is, that only works if the user is able to understand what a movement does and know exactly where the cursor ends up after a command.

With non-monospace fonts that is not possible, as users have no clear idea where the cursor will end up after, say, pressing j or k.

That's the point.

Do you often use j or k? I know I don't. Text objects (word, paragraph, brackets, quotes, sentence, etc) usually do everything I need.
> Do you often use j or k?

Yes, extensively. I mean jk let users navigate between adjacent statements. That's a pretty basic usecase.

In fact, they are used more often than i or l as word movements express intent more clearly than moving a character at a time.

>Do you often use j or k

All the time. All the more so because I code using vertical alignments.

One way is to use emacs and use evil-mode for vi behaviour.

I use proportional fonts for a few things in emacs. It's really nice.

It sounds counter-intuitive to use another editor, especially Emacs, but this might actually be the best advice. Emacs is on top of the game for proportional text editing, as well as the ability to make it behave very much (even exactly so) like Vim.

I'd recommend watching this talk for why: https://www.youtube.com/watch?v=JWD1Fpdd4Pc

I've never understood the attraction of non-monospaced font in an editor.

Especially when you code, where you basically read as much in the vertical direction than in the horizontal.

Monospaced fonts allows for super-fast vertical pattern matching on the code which helps your brain tremendously.

To me, non-monospaced font in an editor is exactly as if each letter in a line of text was placed at a somewhat random height, a very unpleasant experience.

I don't understand.

Doesn't vertical pattern matching works the same for monospaced and proportional fonts? The same words are still the same size.

>The same words are still the same size

Try to properly vertically align code for a matrix containing expressions with X's and Y's in a non-monospaced font.

I see.

That's kinda specific though, and not all code has matrices in it. But I get your point.

> not all code has matrices in it

It's not just matrices.

An array of colors in hexadecimal is a good example of something that will make your eyeballs bleed with a non-monospaced font.

I also tend to do matrix-style aligment with complex expressions that have repetitive patterns.

I see.

I tried using a proportional font for ~15 minutes and didn't encounter these problems, I guess I'll try a bit longer and keep your point in mind.

"I've never understood the attraction of non-monospaced font in an editor."

I need to use some special characters which are only available in certain proportional fonts. They are simply not available in any monospace fonts, so it's impossible for me to do what I need to do without them.

Even if those characters were available in a monospace font, I just prefer the look of some of these proportional fonts, so would prefer to use them for purely aesthetic reasons as well.

This is not for coding purposes, for which I do prefer monospace fonts, for alignment reasons. But if it was possible to get monospace-like alignment with proportional fonts, and a clear distinction between the characters 0O1l;:,.`', then I might prefer them for coding as well, since there seem to be a much greater choice of proportional fonts than monospace fonts.

On the other hand, I'm pretty happy with using Inconsolata for programming, so I'm not sure I'd switch. But it'd be nice to have the choice.

From a comment I made below:

How much would you like to read non-monospace code with an array of colors encoded in hexadecimal ?

As I said, for coding I'd only use a proportional font if I could get monospace-like alignment from it (and if I could distinguish the 0O1l;:,.`' characters in it as well).

Effectively, this means I'm stuck with using only monospace fonts for programming. This is a limitation that I wish I didn't have, as there are far more proportional fonts out there than monospace fonts.

In many proportional fonts, numbers and certain punctuation, like "#", have the same width. In others, you can explicitly select "table figures" to get this effect.
Why not use fontforge to grab the characters out of the proportional font and add them to the monospace font?
Yes, your editor needs to support elastic tabstops. http://nickgravgaard.com/elastic-tabstops/

The main reason why I stopped using a non-monospace font is that elastic tabstops are not available everywhere and thus no real codebase uses it.

I minor second reason is that I did not find a coding-focused non-monospace font. For code you have to clearly distinguish I and l and 1, O and 0, etc. Nobody optimizes non-monospace fonts for that. It seems that there is now at least one such font: http://input.fontbureau.com/info/

For the Emacs users wanting to try this…

  M-x variable-pitch-mode
Vim users, I can assure you that Evil is a really good implementation of Vim, which happens to run in a really good environment.
Unfortunately, this requires the use of gui-emacs, while my entire emacs config is geared towards use from a terminal.
Yes, emacs GUI is more fit for purpose. If you use a terminal emulator you have to choose one or the other (assuming you even can) while emacs allows you to mix and match at will, even within the same file.

I fully expect nobody will try emacs due to religious reasons, though.

Monospaced fonts also mean monospaced puctuation. Punctuation is super important in programming languages. In human-human languages, a comma, a dot or a semicolon is mostly just icing on the cake. There are examples where it can completely change the meaning of a sentence, but for most part puctuation errors are easy to spot, meaning can be inferred and it's largely a matter of taste. In human-computer languages, a misplaced punctuation character really shakes things up.

Summary: monospaced fonts give punctuation weight equal to words, which is how it works in programming. I want non-alphanumeric characters like ,.;:`'"[]()}{!@#$^%%^*&() stand out. Notice how the left part of characters I just listed are hard to distinguish at a glance? And what if I need to count adjacent underscores, spaces or semicolons? Variable length characters are optimised for prose and human-human communication.

Nonsense. Monospaced fonts do not give punctuation weight equal to words. Fonts that give punctuation weight equal to words do. See for example the Input font family:

http://input.fontbureau.com/

I'm surprised that most comments here are just avoiding the problem saying that nobody would want a non-monospace font in an editor, without trying to understand the original reason for this and even think about the fact that someone might be using vim a different way.
I switched from vim full-time to using vscode with the vim plugin for most things. The plugin has gotten better over time and at this point all of my familiar bindings just work as they do in vim. Changing the font is easy.