Sunday, January 17, 2010

Programming Fonts

Over the years, I've tried a lot of different fonts for writing code. Code is different from regular narrative text. Code has more defined structure to it, where certain items need to line up to better understand the context and meaning of the code. Most languages don't enforce such structure, but coding conventions and good style guidelines do. Invariably, monospaced fonts are required to meet these guidelines. I've seen people code with proportional fonts, and it is clear that they are missing out on the organizational properties provided by monospaced fonts. Fortunately, the font is not part of the code itself, so each programmer is free to choose the font he likes best.

While I've tried a lot of fonts, I've only used 4 fonts for day-to-day work. These are my personal favorites as I find them to be clear and easy to read. The screenshots below were all taken of the fonts as displayed in jEdit. The font size in all screenshots is 16. I generally set my font size to 11, but I increased the size for the screenshots so it is easier to see the finer details. I took these screenshots on my laptop, so I have jEdit set to render fonts with subpixel anti-aliasing.

Courier New
I used Courier New for years. When I first started programming professionally, I was on Windows 3.0. Courier came with, and is a good, solid font.



There are a few problems with Courier that caused me to start looking for a new font. First is the lowercase L and the number 1 look very similar. There is not a big distinction between uppercase O and number 0. There is also not much distinction between curly brackets and round brackets. So I looked around and found the Bitstream font family.

Bitstream Vera Sans Mono
This is a very nice, crisp, clean font.


There is good distinction between number 1, lowercase L, and uppercase I. Zero and uppercase O are unambiguous, with zero having a dot in the middle. My only issue with this font is the curly brackets are distorted at smaller font sizes. I generally use font size 11 for writing code, and curly brackets are a bit scrunched, and even more so in comments. I used this font for a good number of years, then I found Inconsolata.

Inconsolata
This is a modern font developed specifically for programming work. It is based on the Consola font that is distributed with Windows Vista. I used it for a while, but the lowercase G bothered me. I know that is a really minor thing, this is really a great font.



One other minor issue with this font is the single and double quotes are slightly curved. There is a "dz" version of Inconsolata (google inconsolata-dz) that replaces the curved quotes with straight quotes, which is nice. Also, the lowercase L looks a lot like the number 1 in a lot of other fonts. It's easy to tell that the number 1 is a one, but not so easy to tell if the lowercase L is an L or a one when it is not right next to a one.

DejaVu Sans Mono
Currently, I'm using DejaVu Sans Mono, and have been for the past few months. It looks very clean and crisp on both my laptop screen and on the LCD screens I have at work. DejaVu is a modern replacement for the Bitstream Vera font that I used for years, so it's not surprising that I like this font.



This font has all the good features of Bitstream Vera, and it scales better. The curly brackets are not scrunched at smaller font sizes. Like Bitstream Vera, it retains the mini-serifs on the upper and lower case I and J and on the lower case L, which adds a little bit of flair to this font and helps distinguish the upper case I from the lower case L and the number 1.

Update:

Source Code

Adobe released an open source font today for programming called "Source Code". It looks like this:


Since I just installed it today, I haven't had an opportunity to really get an impression of it, but at first glance, it looks a lot like DejaVu Sans Mono. There are some subtle differences worth pointing out:
  • The numbers are a little shorter.
  • The Q has a more pronounced tail, as does the comma and semi-colon.
  • There is less separation in the !, which may cause it to look like a 1 or l.
  • The | is slanted in italics, where the | in DejaVu Sans Mono is not, which may cause it to be mistaken for /.
  • The overall spacing seems better than DejaVu Sans Mono, although the line spacing is a little too tall, I think.
Overall, it looks good and I'll give it a try for a while at least. For actual use in jEdit, I've set the font size to 12, anti-alias smooth text to subpixel HRGB, and extra vertical line spacing to -1. The -1 helps pull the lines a little closer together.

1 comment:

exhuma said...

Hi,

First of all thanks for this nice overview.

I came across this because of the new Adbobe "Source Code" font. I also made a comment over at their site regarding more exotic glyphs (like U+2423 'OPEN BOX' which is used to visualise a space).

Have you looked into these features as well on the other mentioned posts?

On the other hand, I feel that there are other fonts missing, like "Consolas", "Lucida sans mono" and "Droid sans mono".