62

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?

17
  • 11
    I like proportional fonts for reading, but I strictly use monospaced fonts for code. Always, always, always. Commented Sep 20, 2010 at 8:08
  • 14
    To also quote Wikipedia: [citation needed] :) Commented Nov 6, 2010 at 17:31
  • 7
    Many years ago, a prof I had in college half-jokingly said "... because it's not programming unless it's courier new." Commented Nov 18, 2010 at 15:58
  • 16
    My reason for using a proportional font is very simple. It’s not the 1980s anymore. We’ve moved on from character terminals. Newspapers, books and websites generally don’t use monospace fonts for reasons of readability. I think they have a point.
    – Timwi
    Commented Feb 20, 2011 at 0:07
  • 6
    Verdana 11px is great. Commented Apr 9, 2012 at 15:29

11 Answers 11

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!

11
  • 14
    Really, there's just one big fat point against proportional: you can't really align because nobody cares for elastic tabstops. Which is utterly odd, given how it benefits both the monospaced die-hards and those who actually prefer reading good-looking variable-width fonts. Come on, world! Elastic tabstops! Commented Feb 28, 2012 at 10:30
  • 7
    @romkyns: Adopt an indent style that doesn't rely on lining up with other lines. Simple.
    – Zan Lynx
    Commented Apr 9, 2012 at 22:28
  • 4
    @ZanLynx I did, because I like proportional fonts more than I like vertical alignment at places other than the start of the line. Commented Apr 11, 2012 at 18:47
  • 1
    @badp Have you found a proportional font where you can distinguish two single quotes from a double quote? I would love to try using a proportional font, but this issue has always held me back. Neither of these are the same: '''', '"', "", "'', ''" ('''', '"', "", "'', ''") Commented Mar 6, 2019 at 13:34
  • 1
    @JanAagaard I use editor colour for that. Single quote strings are pastel yellow, double quote strings are pastel mauve, and (with Verdana and Notepad++ anyway) I can pretty easily tell which is what from your example when on a black background. The last comma is mauve, for example, because unlike the rest it's actually in a string. I can also fairly easily pick out what's what from a random string of them mixed together ( ''"''''"'''''''''"'""''''''""'""'' and I can tell which is which and the nesting), which is a skill I don't actually need at all because my code never looks like that. Commented Apr 15, 2020 at 22:57
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.

22
  • 11
    This happened because you used spacing that happened to match the monspace font. If you had proper spacing w/r/t the proportional font, you wouldn't have this problem.
    – Kos
    Commented Apr 11, 2012 at 19:30
  • 6
    @Kos: so instead of pressing, say, three tabs, you would press fifteen times the space key, than notice that you typed too much, and remove the last space? Seems a bit too complicated, don't you think? Commented Apr 12, 2012 at 2:26
  • 6
    Eclipse actually supports using a different font for rectangular select mode, which makes this less of a problem.
    – Nicholas
    Commented Aug 19, 2012 at 17:11
  • 8
    @Kos RE: "proper spacing w/r/t the proportional font": But then if a different programmer uses a different font on the same file, it won't line up. If all editors use monospace fonts, it'll always line up (assuming the code doesn't abuse tabs for alignment).
    – Max Nanasy
    Commented Aug 22, 2014 at 1:01
  • 10
    I'm using a proportional font for 2 years without any elastic tabstops. I do not use rectangular selections because there is something else that completely replaces it in most IDEs: multi-caret selection. In this example I would select "MyReputation = " then press Select next occurrence using CTRL-D in SublimeText and VSCode, ALT-J in IntelliJ / JetBrains editors. Next, SHIFT-CTRL-RIGHT ARROW to expand the selection to the next token at the right and it's done. Main advantage is that no one needs to align stuff to edit. Disadvantage, if you have something aligned, it will no longer be.
    – Hay
    Commented Oct 2, 2016 at 19:30
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.

6
  • 10
    Love your comment mini-battle with microsoft on that bug. And their cheery response which is basically "Hi! Thanks! Great to meet you! We're gonna do nothing. OK, thanks lovely to chat with you!" Just imagine if people acted like that in real life...
    – danio
    Commented Sep 20, 2010 at 11:24
  • 2
    You get an upvote for sympathy, since, though I don't use a proportional-width font for some of the very reasons you cite, my inner typographer constantly yearns for proper editor support, in design and programming alike.
    – Jon Purdy
    Commented Sep 20, 2010 at 11:55
  • Weird, I was just thinking that punctuation is actually harder to differentiate (particularly full stops) because it takes up less space. I also remember that Notepad++ used Comic Sans MS on comments for the longest time. Commented Sep 22, 2010 at 11:28
  • 6
    If you find punctuation hard to identify in a monospace font, there are other monospace fonts - it doesnt mean you need to use a proportional font.
    – Nobody
    Commented Nov 18, 2010 at 15:45
  • Exactly for better punctuation, I sometimes use EnvyCode A or B.
    – zanlok
    Commented Nov 1, 2012 at 7:35
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.

2
  • 4
    I fully agree. And with tabs (as opposed to hard-coded spaces) you can switch between monospace and proportional fonts and adjust the tab width accordingly. What I have yet to see, though, is an editor in which you can set the tab width in units of EMs. Commented Sep 8, 2012 at 11:37
  • Can I change your tabs to pixels without a quarrel? Commented Apr 3, 2021 at 14:14
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.

4
  • 4
    I’m surprised you like Arial and Verdana. I find them a bit rough and unprofessional. Have you tried Calibri?
    – Timwi
    Commented Feb 20, 2011 at 0:05
  • 2
    I'm using 8pt Verdana. Long identifier names are easier to read. I can view 70 lines of code without scrolling and lines are much shorter, so the code is a narrow column, like in a newspaper. This enables me to split the editor's view into two vertical columns: I view the declaration in one view and write code in another. Also when debugging, the screen is full with debugging windows, the code view fits in the small space. Using proportional fonts is remove the desire to vertically align things and put ascii boxes of asterisks around the comments.
    – Calmarius
    Commented Feb 27, 2012 at 20:59
  • 2
    I see 147 lines of code in Visual Studio on a 1920x1200 monitor rotated 90° for a portrait mode, using with Lucida Console font.
    – zanlok
    Commented Nov 1, 2012 at 23:03
  • 158 lines with Monaco font in Vim... My screen isn't even HD Commented Jul 30, 2016 at 18:53
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.

2
  • 1
    Checking page 5 of my Special Edition: proportional fonts are generally considered as better for text, using them allows fewer illogical line breaks, and most people get used to it. I find it easy to read. Stroustrup is presenting code here, not trying to create it, and that may make things different. Commented Dec 30, 2010 at 16:18
  • 4
    @David, yes, he is presenting code. But, it is presented for "reading" and the very question of fixed vs proportional is for "reading" code, IMHO.
    – Nivas
    Commented Dec 30, 2010 at 17:38
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.

1
  • This is the most accurate answer as it discusses preference, which is what the original question was about. A bunch of answers here try to pretend that there is an objective answer, and then spend time talking about irrelevant software packages that have nothing to do with personal preferences as they apply to font spacing. Commented Apr 3, 2021 at 14:20
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

2
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.

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?

3
  • 2
    Verdana has serifs on I for easier differentiation.
    – Calmarius
    Commented Jul 25, 2012 at 19:40
  • 1
    0 and O is another major problem. Also ' vs ` and . vs , as well. Sometimes & and $ are a problem (worrisome in perl/php) However, Verdana is good for most of the above although not great at 0s. Sadly, on existing projects with tabs mixed with evil spaces, I usually give up and use Lucida Console. If you're asking about variable naming, though, you're not using modern code completion or at least copy/paste like you should.
    – zanlok
    Commented Nov 1, 2012 at 7:47
  • One proportional font I know that has unambigous 0Oo1lLiI is TeX's "Latin Modern Mono Prop", a proportionally spaced relative of "Latin Modern Mono" which was absolutely designed for code (for print not screen, though, I find the rendering a bit blurry). Punctuation is still a problem, has too little spacing for its importance in code IMHO, and creates ambiguties e.g. two single quotes vs one double quote: '' vs ", '' vs " Commented Dec 15, 2016 at 15:41
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.

4
  • 2
    I'm interested to know what environment this is a problem for you. You can use tabs with both proportional and fixed width fonts to line them up in columns. Where the issue arises is if you use spaces instead of tabs.
    – temptar
    Commented Feb 28, 2012 at 13:48
  • 3
    @temptar: consider "iii12345", "AAA12345" and "nnn12354" one above each other. The mistake ("345") is much easier to spot. you can't put tabs in the middle of a value.
    – Adam Matan
    Commented Feb 28, 2012 at 13:58
  • 1
    @temptar Tabs are not recommended by Python, and their width varies in different editors, which might lead to misaligned code.
    – Adam Matan
    Commented Feb 29, 2012 at 8:56
  • 3
    @Adam Matan Which is exactly why you shouldn't do fancy formatting. Commented Sep 8, 2012 at 11:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.