Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

closed as not constructive by Jarrod Roberson, ChrisF Apr 9 '12 at 18:14

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

10  
I like proportional fonts for reading, but I strictly use monospaced fonts for code. Always, always, always. –  Frank Shearar Sep 20 '10 at 8:08
6  
To also quote Wikipedia: [citation needed] :) –  dr Hannibal Lecter Nov 6 '10 at 17:31
4  
Many years ago, a prof I had in college half-jokingly said "... because it's not programming unless it's courier new." –  Steve Evers Nov 18 '10 at 15:58
8  
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 Feb 20 '11 at 0:07
3  
Verdana 11px is great. –  Czarek Tomczak Apr 9 '12 at 15:29

12 Answers 12

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.

share|improve this answer

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.

share|improve this answer
6  
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 Sep 20 '10 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 Sep 20 '10 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. –  DisgruntledGoat Sep 22 '10 at 11:28
3  
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. –  rmx Nov 18 '10 at 15:45
    
Exactly for better punctuation, I sometimes use EnvyCode A or B. –  zanlok Nov 1 '12 at 7:35

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.

share|improve this answer
    
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. –  David Thornley Dec 30 '10 at 16:18
2  
@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 Dec 30 '10 at 17:38

You can pry my monospaced font from my cold, dead, still-trying-to-program hands.

share|improve this answer

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 Ubuntu 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!

share|improve this answer
    
I didn't realise that the Ubuntu font had been released. I think it works well there. –  Alan Pearce Nov 18 '10 at 15:34
    
+1 for showing me WenQuanYi Zen Hei Mono, that font is amazing. I’ll almost certainly use it in my thesis. Depends on how well it looks printed – on screen it looks amazing and doesn’t take a lot of horizontal place, which is very important in print. –  Konrad Rudolph Jan 28 '11 at 22:09
3  
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! –  romkyns Feb 28 '12 at 10:30
2  
@romkyns: Adopt an indent style that doesn't rely on lining up with other lines. Simple. –  Zan Lynx Apr 9 '12 at 22:28
2  
@ZanLynx I did, because I like proportional fonts more than I like vertical alignment at places other than the start of the line. –  romkyns Apr 11 '12 at 18:47

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.

share|improve this answer
1  
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. –  August Karlstrom Sep 8 '12 at 11:37

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.

share|improve this answer
    
I’m surprised you like Arial and Verdana. I find them a bit rough and unprofessional. Have you tried Calibri? –  Timwi Feb 20 '11 at 0:05
1  
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 Feb 27 '12 at 20:59
    
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 Nov 1 '12 at 23:03

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

share|improve this answer

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.

share|improve this answer
1  
Excellent point. I rarely ever use rectangles, but when I do, they're indispensable. –  Jason Baker Oct 2 '11 at 16:49
    
Have you actually tried it? It works perfectly well with a proportional font in Visual Studio 2010. –  romkyns Feb 28 '12 at 10:27
2  
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 Apr 11 '12 at 19:30
2  
Eclipse actually supports using a different font for rectangular select mode, which makes this less of a problem. –  Nicholas Aug 19 '12 at 17:11
1  
@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 Aug 22 at 1:01

Never, ever, because Monospaced fonts allows me to compare different attributes.

Compare:

name1=["William", "Shakespear", 1564, "Peotry"]

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

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

To:

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

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

share|improve this answer
1  
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 Feb 28 '12 at 13:48
    
@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 Feb 28 '12 at 13:58
    
@temptar Tabs are not recommended by Python, and their width varies in different editors, which might lead to misaligned code. –  Adam Matan Feb 29 '12 at 8:56
1  
@Adam Matan Which is exactly why you shouldn't do fancy formatting. –  August Karlstrom Sep 8 '12 at 11:42

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.

share|improve this answer

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?

share|improve this answer
2  
Verdana has serifs on I for easier differentiation. –  Calmarius Jul 25 '12 at 19:40
    
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 Nov 1 '12 at 7:47

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