5

Possible Duplicate:
Why use monospace fonts in your IDE?

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

Community
  • 1
  • 1
user128807
  • 10,447
  • 17
  • 53
  • 72
  • @Janusz. I'm working on this. Thanks for the reminder. – user128807 Jun 23 '10 at 07:47
  • Maybe that question should become a community wiki question - it doesn't seem that there will be any single definitive answer that can be accepted, more like a place where everyone can give his point of view. – Jean Hominal Jun 23 '10 at 08:25
  • 1
    I think this is pretty obvious and becomes clear to you if you try coding without a fixed width font for a while. – sloth Jun 23 '10 at 10:29
  • 2
    seems to be a near exact duplicate of http://stackoverflow.com/questions/218623/why-use-monospace-fonts-in-your-ide – Jean Hominal Jun 23 '10 at 11:58

10 Answers10

10

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.

EMP
  • 59,148
  • 53
  • 164
  • 220
  • 5
    No reason why tabs couldn't align text just as effectively. – Barry Brown Jun 23 '10 at 07:56
  • 2
    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 Jun 23 '10 at 08:37
  • 1
    @detly: http://nickgravgaard.com/elastictabstops/ –  Jul 13 '10 at 02:06
9

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
  • 186
  • 3
  • 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. – Jean Hominal Jun 23 '10 at 08:04
6

Just try a non fixed-width font.

miku
  • 181,842
  • 47
  • 306
  • 310
5

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
  • 670
  • 1
  • 5
  • 10
5

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
  • 7,309
  • 3
  • 50
  • 91
  • you dont need a fixed width to use column 1 or 6, but it would get real ugly if you did this with non fixed width fonts. – arana Oct 06 '22 at 20:21
3

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.

Jean Hominal
  • 16,518
  • 5
  • 56
  • 90
2

typos/missing letters can be seen clearer

Sergey Eremin
  • 10,994
  • 2
  • 38
  • 44
2

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

Jim
  • 633
  • 1
  • 6
  • 9
1

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.

Dalbir Singh
  • 2,629
  • 3
  • 26
  • 29
  • 4
    This choice is not between fixed-width and fonts like Comic Sans, that's a false dichotomy. –  Jul 13 '10 at 02:01
1

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.

Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61