Variable width fonts for code

I know that the topic of appropriate fonts for code has come up quite a few times on Typophile. I spend a good portion of my time in code of one kind or another, and find myself using mono width fonts very infrequently. To many programmers, it's a heresy, but I can't really see any good reasons to use mono-width, except when the output depends on uniform character widths for formatting like in the shell.

Are there any other variable width programmers out there? What types do you use? I usually use Verdana, because it's pretty unambiguous on the screen (particularly the braces/brackets/parens).

Christian Robertson
14 Jun 2005 — 5:22pm
General Discussions

Although I can see a lot of good reasons for using a mono font for programming, I'm still interested in hearing arguments from the Opposition - so I hope this thread flies.

hhp

I use variable-width for code for the same reasons I use them for everything else. My 'meaningful variable names' are more meaningful when I can read them quickly. I also prefer that lines not wrap while I'm coding, so variable width helps get more on a line without scrolling. I have to admit that it's probably an aesthetic thing too.

It depends on the language and the comment style. If something compells you, with your agreement or not, into

//*************************************
//* DRAWING ASCII ART AROUND COMMENTS *
//*************************************

then you want monospace. When I first got into Python, I asked EvB about a monospace version of Python-Sans. He said there was one, but he didn't find it particularly necessary for coding Python, and I eventually came to understand.

So our world now has all these programmers to the East. I'd be surprised if some of them haven't already come up with a much cooler, more usable programming language that I don't know about because they no longer saw the need to base their programming language on English. Non-English-based programming languages certainly do exist, but really only recently has Unicode complex script support become so ubiquitous and affordable. So I'm wondering if there's some cool new language that eclipses both Python and Mathematica and could be mine if I only bothered to learn some rudimentary Mandarin.

The only reason I need to use mono fonts is that WinEdt (which I use for TeX) will only let me use mono fonts. I sometimes use Bitstream Vera Sans Mono, but usually I use Lucida Console. I really would prefer to use a variable width font in WinEdt ...

I remember Adam T (and I think others too) pointing out some quite good reasons to use a mono font for programming. Could somebody unearth that thread? Was it the one -or one of the ones- that dealt with ClearType too?

hhp

From what my programmer pals have told me they find it earier to find differences between lines of text if they can scan the pattern rather than 'read' the code. I am sure they do both really - but the scan comes first. It may be a matter of habit too. If you train to code in mono & then you try to look at something in variable it probably streaches the brain in a new uncomfortable way. Maybe if you learn to code in variable it is different. Python is pretty english like I think from what I have seen of the code so that might account for the EvB's comments too.

I am very intertested to hear more about this topic too since I am making a font called 'software developer' for coding in right now.

Non-English-based programming languages certainly do exist

Not to veer too far off-topic, do you have any examples of that? I've always been curious about that.

as for why to use monospaces, I think eben's 'pattern' argument makes sense. I also like to use a lot of ASCII comments, so there's that too.

That said, I bet much of it is just "it's what people are used to"

I think the use of monospace fonts is largely historical, dating back to punched cards and line printers. There is some historical precedent for use of proportional fonts for programs, and there's nothing inherent about programming that requires a monospace font.

Research papers and academic books in the 1970's, e.g. from the likes of Dijkstra and Wirth, would typeset programs with keywords in boldface and such. This was all academic stuff, though, and I don't think anybody had any systems that actually allowed one to edit and execute programs written this way; it was all book stuff.

An early use of proportional fonts for actual programming was the SmallTalk system at Xerox PARC starting in the late 1970s. The SmallTalk system featured a graphical programming environment with an integrated editor. I don't know what font was used, but it was a proportional sans-serif face. This (supposedly) resulted in some howlers. In one case there was a button labeled "DoIt" (to tell to computer to perform some action) but a user misread it as "dolt" and became offended.

Personally, I prefer editing programs in monospace, and everybody in my shop uses monospace. (We use C, C++, Java, and various scripting languages such as sh and perl.) As I said above, I believe this is mostly historical. For most things I suspect a proportional font -- one in which problem characters are distinct -- would work just fine.

There are a handful of cases, however, where it really is necessary to have things line up properly. It's not just boxes around comments; sometimes horizontal alignment conveys important information about the program. For example, a table containing string and numeric constants should have its columns lined up. Or, mathematical expressions spanning several lines could have various terms lined up in order to make the structure of the expression more clear. It's probably possible to do this in a proportional font with the right tab settings in place, but in a monospace font it's much easier just to insert the right number of spaces.

s'marks

Hrant, I believe the thread you are referring to is here.

Stuart, thanks for the insights.

Zara, yes! Thanks. Strange that I forgot
it was the thread where Coda was born...

hhp

This is a GRrrrreat thread.

Thanks Zara!

As a programmer, the primary reason to use monospace fonts is because they make it easier to line up elements vertically.

[example omitted, since SmartyPants insists on removing whitespace even in code blocks]

While it might be possible to define a system where an 'i' was one fixed unit long, an 'o' was two units, an "m" was three, etc., it would be a hassle with no real benefit. Also, it would cause all existing code to not line up properly.

Code isn't read like a novel; it has unique legibility requirements. It is vital, for instance, that the reader can accurately identify each character individually, and tell similarly-shaped symbols apart. At the same time, it is far less important to be able to recognize words as whole shapes.

I agree with bergamot's comment about monospace fonts making it easier to line up elements vertically. This can help to convey important semantics about the program, much as indentation helps to convey lexical nesting level.

However, I wonder which way the causes and effects run.

Is it: (a) "Lining things up is a requirement, therefore it's necessary to write programs in a monospace font" ?

Or is it (b) "If one is programming in a monospace font, it's easy to line things up, so this technique is often used to help convey information about the program" ?

My leaning is toward (b). The reason is that there are several examples of programming environments that use proportional fonts, including Python, SmallTalk and AppleScript. People seem to have a lot of success with these languages/environments, despite -- or because of -- their use of proportional fonts. It might be that the loss of the ability to line things up easily is offset by other advantages offered by using a proportional font. I don't have any personal experience using these systems, though.

Above, johnbutler mentioned that he "eventually came to understand" about using a proportional font for Python. John, I'd be interested in more details about what you mean by this.

s'marks

I think this has been covered in another thread - but - I think the stucture of the programming languages themselves probably give rise the typographic preference. If the language is more like regular written text - the proportional expression is probably fine. If the language was invented with the assumption that monospace would be used and it uses a lot for formula style expressions it probably is easier to code in monospace.

View original article