63

I was reading the wikipedia article on programming style and noticed something in an argument against vertically aligned code:

Reliance on mono-spaced font; tabular formatting assumes that the editor uses a fixed-width font. Most modern code editors support proportional fonts, and the programmer may prefer to use a proportional font for readability.

To be honest, I don't think I've ever met a programmer who preferred a proportional font. Nor can I think of any really good reasons for using them. Why would someone prefer a proportional font?

Jason Baker
  • 9,653

11 Answers11

54

Common points against proportional fonts, commented.

  • You cannot precisely align code vertically with proportional fonts. I mean, you could precisely align code vertically with proportional fonts, if everybody was using elastic tabstops, but alas...
  • Some proportional fonts make it hard to distinguish some characters groups. (e.g., mrnm). Not all programming fonts are perfect either, however: Courier New has identical 'O' and '0' and identical '1' and 'l'.
  • Some IDEs have poor support for non-fixed-width fonts (like aforementioned Visual Studio or Python's IDLE). In some contexts, also, you just can't use one. (e.g., terminals.)
  • Choosing a proportional font for coding will get you in endless holy wars. Here, however, the problem exists between the keyboard and the chair.

Points in favour of proportional fonts

Personally, I've been using both the 'Ubuntu' font and WenQuanYi Zen Hei Mono with pleasure and find myself unable to prefer one to the other. :)

Ubuntu
WenQuanYi Zen Hei Mono
Ubuntu 10 and WenQuanYi Zen Hei Mono 9, compared. There's no clear winner here, if you ask me.

That said, fonts are like food. Some like them well rounded, some like them hot and spicy -- there's no one right font, or all of us would be using it right now. Yay for choice!

badp
  • 1,890
34

There is a reason which makes it practically impossible to use fonts other than monospace for coding, but was not mentioned in other answers: rectangular selections.

This feature, often not very useful and not very known when working with ordinary text, is essential for developers. You may imagine a multitude of scenarios: removing // comments on several lines, adding parenthesis or other characters, etc. This is even more valuable with advanced support of rectangular selections, as in Visual Studio 2010, where you can not only select and remove text, but select and replace it.

Let's take an example:

private IEnumerable<SELove> StackExchangeRocks()
{
    var howILoveSEWebsites = new []
    {
        new SELove { SiteName = "Stack Overflow", MyReputation = 5269,  MyRating = Rating.Outstanding, },
        new SELove { SiteName = "Programmers",    MyReputation = 16937, MyRating = Rating.Outstanding, },
        new SELove { SiteName = "Super User",     MyReputation = 650,   MyRating = Rating.QuiteGood,   },
        new SELove { SiteName = "Server Fault",   MyReputation = 489,   MyRating = Rating.Good,        },
        // Initialize other websites here.
    };

    return howILoveSEWebsites.OrderByDescending(c => c.MyRating);
}

private class SELove
{
    public string SiteName { get; set; }
    public int MyReputation { get; set; }
    public Rating MyRating { get; set; }
}

private enum Rating
{
    Outstanding,
    Good,
    QuiteGood,
}

In this legacy code, I want to replace in-code rating by a method which will load my rating from Stack Exchange websites themselves, being able to always have an up-to-date data. I started to refactor the MyReputation property, and now I want to remove the initialization, in scope. Imagine that I have not four, but all 84 SE websites.

Here's what happens when using Consolas, a monospace font. I press Backspace, and that's all, I can spend the remaining time to do something actually useful.

The image shows that with Consolas, the rectangle selects reputation property.

And here the same thing with Segoe UI. Ouch!

The image shows that with Segoe UI, some reputation properties are selected only partially, while on other lines, the beginning of rating property is selected.

16

I used to use a proportional font, mostly because I find punctuation is actually easier to differentiate, but over time I've given up because nobody else does it and everybody unconsciously assumes mono spaced fonts (as the wikipedia article mentions, trying to do tabular formatting, ascii art in comments and so on).

Plus, issues in Visual Studio, that Microsoft don't want to fix, basically make it impossible to use well-designed proportional fonts anyway.

Dean Harding
  • 19,911
11

Personally I don't care. As long as you keep my tabs aligned and the font legible, I couldn't care less whether I use monospace, proportional, or some other off-the-wall spacing. Just don't start substituting my tabs with spaces, and you'll have no quarrel with me.

Aeo
  • 885
7

I use a proportional font (Arial is the best I've found so far, Verdana a close runner-up) and honestly I'm still bemused that people use fixed width fonts; why would you want to sacrifice readability like that? I could understand if tabular formatting were desirable, but it isn't, since it creates a maintenance nightmare regardless of font.

rwallace
  • 1,208
5

I spent some time finding a good, readable font for Eclipse a while back, and under XP I used Verdana for quite some time. Consolas settled that because it is truly superb for programming.

These are my findings:

  • Most proportional fonts are designed for prose and only little punctuation (which in turn is usually one or rarely two characters). The C family of languages have lots of punctuation, which simply does not - in my opinion - look good and is harder to read than necessary.
  • Variable length characters mean that the length of lines vary. This makes it close to impossible to guess where the cursor will end when navigating using arrow buttons. I found this annoying.
  • Vertical spacing matters too. This is normally not something that can be overridden easily, and most proportional fonts have less room between the lines than I'd like.
  • Very few IDE's are tested with proportional fonts. This makes room for subtle bugs like putting the cursor in the wrong location, incorrectly repainting characters, and the like.

Hence I found that it was not worth the trouble for me.


Note on alignment and other layouts: I have set Eclipse to auto-format each file on every save, so all fancy layouts are automatically reset. Eclipse uses tabs instead of multiple spaces and these can be positioned correctly even with proportional fonts. Hence formatter layouts can be over one another, but we use the standard formatter configuration which does not have that.

I believe that the enforcement of automatic formatting for everyone on every save minimizes the false positives in the source control system, when doing forensic analysis.

5

I remember in Bjarne Stroustrup's book The C++ Programming Language, propotianitely spaced fonts was used for code. (I am unable to find any sample pages on the web)

I don't remember the exact reasons, but think he mentioned this and one another change (I think the C++ language itself) as a new introductions in that book.

Personally, I prefer fixed space ones. Consolas is my favorite.

Nivas
  • 526
  • 2
  • 5
4

For languages that have short lines and lots of open space, I prefer monospaced fonts. I find that variable width fonts can improve readability where you have long lines and dense syntax.

The problem with most proportional fonts is that they weren't designed for programming. This page shows some fonts that were.

Trim font

3

Smalltalk environments like Pharo use proportional fonts and due to the language style it looks very good there. But in C-style languages like Go or others like Erlang or Python I prefer monospaced fonts.

themue
  • 281
  • 2
  • 6
1

Never, ever, because monospaced fonts allow me to compare different attributes.

Compare:

name1=["William", "Shakespeare", 1564, "Poetry"]

name2=["John", "Locke", 1632, "Philosophy"]

name3=["Jonathan", "Littell", 1967, "Prose"]

To:

name1=["William",  "Shakespeare", 1564, "Poetry"     ]
name2=["John",     "Locke",       1632, "Philosophy" ]
name3=["Jonathan", "Littell",     1967, "Prose"      ]

Or:

a = "iii12345"

b = "AAA12345"

c = "nnn12354"

To:

a = "iii12345"
b = "AAA12345"
c = "nnn12354" # The mistake ("354") is much easier to spot.

The proportional fonts just can't place equivalent attributes exactly one above another.

Glorfindel
  • 3,167
1

While I do feel that proportional fonts are prettier, in some of them, especially sans-serif fonts, its impossible to see the difference between an "I" and an "l". Wait, what did I name that variable again?

Billjk
  • 1,249