views:

266

answers:

11

Possible Duplicate:
Why use monospace fonts in your IDE?

Virtually all coders (and code editors) use fixed width fonts. Why is this?

+10  A: 

Probably because it makes the code easier to scan - you have "blocks" of code, ie. text that lines up vertically far more often than you would in normal prose. If the font is not fixed width than it wouldn't be visually aligned.

Evgeny
No reason why tabs couldn't align text just as effectively.
Barry Brown
Unless you have leading text eg. `Function( -> Param1\n -> -> Param2)`. Do you need one tab or three on the next line? Depends on the font width and tab size. You might also do things like `const int thing1.=........1\nconst int otherthing2.=...2`, etc.
detly
@detly: http://nickgravgaard.com/elastictabstops/
Roger Pate
+5  A: 

Just try a non fixed-width font.

The MYYN
Like "Comic Sans MS" :)
Andrew Russell
...or some fancy decorative or gothic font, your sources will be much more pleasant to look at... and atmospheric;)
el.pescado
+1  A: 

typos/missing letters can be seen clearer

kgb
+3  A: 

Because it helps with code layout and make it easier to spot errors as lines are a consistent length for a given number of characters.

It is also historical as we used to use terminals with fixed width fonts.

Richard Forss
A: 

open some code in your favourite editor... I'm presuming by default that your text editor will have a fixed-width font set.

Now change the font to Comic-Sans..... enough said!

Seriously though, fixed-width is much much clearer to read.

Dal
This choice is not between fixed-width and fonts like Comic Sans, that's a false dichotomy.
Roger Pate
+1  A: 

Mostly for outlining. However it's also a habit. I come from the old school IDE's while they were still in MS-DOS.

Also companies like Microsoft have made fonts to make it "easier" to code with. I prefer the Consolas font myself while coding in Visual Studio.

Grz, Kris.

XIII
+1  A: 

It's a matter of choice. I personally prefer to use the very elegant Comic Sans or Purisa font for programming.

Jim
Comic Sans? Elegant? Am I missing something?
Jouke van der Maas
+1 for hidden irony;)
el.pescado
+7  A: 

It greatly enhances readability - expecially of punctuation characters which have a very important role in code and which variable width fonts often "squeeze" into minimal space.

TechPreacher
I would add that such a consideration is more important in text editors than in advanced IDEs. Still, +1, because every time you are using a String to write SQL/HTML/other code, the IDE usually does not help you.
jhominal
+3  A: 

I would add a few minor reasons, mainly related to the code's visual flow:

  • You can align variable assignments (or not)
  • One typical example would be aligning table declarations so that it will look like a table in the code.

    var sn        = [ 8349824, 3094230,       1]; // first table line
    var longname1 = [     421,    1324, 5382920]; // second table line
    // Try and do something as readable in variable width font!
    
  • You can agree on a line-width limit that will have a consistent effect.

  • Your code has the same "face" everywhere - whether you read it in a <code> block on the web, in your basic text editor on a remote terminal or in your graphical IDE with antialiased fonts - you will immediately recognize the code.
  • More predictable behaviour when navigating code - when I go up or down, I already know exactly where the cursor will end up.

In short, fixed-width font allows for finer grained control over source code appearance and readability, independant from the availability of any given font.

jhominal
A: 

ask those guys.

Kai
Why is this accepted? (Thanks for the link though, really awesome stuff).
Jouke van der Maas
It puzzled me as well, but I think the asker just rushed to accept *something* when a commenter pointed out the need to increase his accept rate.
Evgeny
I was surprised myself
Kai
@Jouke It is accepted because I believe it is the best answer.
+3  A: 

I know I am a week late to the game but I can't believe that there is no mention of programming languages like FORTRAN that basically required fixed width fonts. Comment chars had to go in column 1, line continuation chars in column 6 and that is not even mentioning the inherent fixed width font effect of punch cards. Mention has been made of fixed width fonts on terminals, but programming predates even that.

Peter M