Development in Variable Width
The traditional font family for use in writing computer code is monospace. Partly this is because monospace was all that was available when computer programming began and remained largely the only choice until relatively recently. Mostly, though, monospace is used because coders use spacing to line up their code to make it more readable.
I visited a website which listed some favorite programming fonts and described the properties of each font which made it suitable for programming. All the fonts were monospace as one would assume. However a commentor on the site said that he began using a variable width font a few years previously and never looked back.
So I’ve decided to give it a try, and so far, I like it. Variable width fonts are just easier on the eyes after a while. Still, you need a decent programming font. I would like one where the parentheses (and brackets) have wider than average spacing, and similar characters such as zero and the letter ‘O’ are distinguishable. Interestingly, I’ve found that when I don’t intentionally line my code up, I actually don’t want it to line up. I have found that it is actually easier to read the code when all the characters in the line below do not line up directly under characters in the line above. My left margin is always clean because the spaces and tabs are always the same size. For the most part, I don’t see spacing as a problem. In my particular font, I wish the space character was bigger, though. Another “pro” is that I can fit a whole lot more on one line without using a small font or a harder to read, narrow font.
There are some “cons” though. That narrow font means that people who wrap their comments to more than one line seem to wrap them way too soon. And using a variable width font means I will, likewise, tend to wrap mine later than would be readable for a monospace-font developer. My left margin is always clean, but every once in a great while, I find that code that was intended to line up does not. However, this hasn’t been a problem for me. Coders, I think, often over-format their code, even reducing readability to some degree.
What I would like to see is an editor that can mitigate the downsides of variable width fonts by manipulating the whitespace and recognizing the language syntax. For instance, the editor should be able to detect when a monospace-font developer adds superfluous whitespace for the purpose of lining up code and then expand the variable width whitespace as necessary to make sure the code is lined up. Though this can’t ever be perfect, it can be perfected to a reasonable degree. Also, comment blocks that are obviously wrapped intentionally could be “unwrapped” then “rewrapped.” There are email applications that do this with email text wrapped to the standard 80-or-so lines. The editor can then automatically wrap comments back to monospace width when saving.
I am currently using KDevelop, KDE’s development environment, for my C++ development. I might just try to find out where the editor code is and see if I can implement something like this. In the mean time, though, I think I’ll keep experimenting with different variable width fonts anyway.
I’ve often thought about this too. Why is fixed width so necessary to the programmer?
I can only think of two reasons which I think you mentioned already: to make certain significant characters more visible (like curly braces and parentheses), and to make the spacing standard so other developers can choose a different monospace font and have no trouble.
Other than that, I can see no good reason. I do have a few questions though:
Why do you think that programmers use fixed fonts when the rest of the world has made the transition away from them as soon as variable width fonts were available? Maybe it’s because I can’t see why tabs don’t do a good job of providing all the “lining up” that any code needs.
What font do you like to use?
What are some examples where you intended to line up code but it doesn’t line up?
I think programmers didn’t switch to variable length fonts because the switch to variable length fonts didn’t happen in their favorite development environments. Ironically development environments are often the last things to see certain innovations because developers get used to doing things a certain way, and also tend to become self-righteous zealots that preach that their way to programming nirvana is the only way. How else can you explain emacs, and even vi’s continued use? Neither of those can yet do variable width fonts.
I’m using Tahoma right now, but I’m sure there are better ones out there. I’d like to mix and match them, actually. I’d like to take some curly braces and angle brackets from monospace and insert them in my variable width. I wouldn’t mind getting my slash or dot back in my zero, even though I can easily tell a zero from the letter ‘O’ because it’s narrower.
Tabs are not quite sufficient in their typical implementation. The only tabs guaranteed to line up are those off the left margin. Once a tab is based off of entered text, the width of that text may span more tabstops in one environment than another causing the tab to be inconsistent.
There are very few cases where code that was intended to line up did not so far. The only ones I’ve seen are when the developer went crazy lining up declarations, or formatted a comment by putting a square border of asterisks all the way around it.
Just as I thought. Most people waste so much time on aligning things to the right of other text. It’s such a waste to bother with this regardless of the font you use. Same thing with asterisks around a comment. It’s a shame to see how much people waste their time when formatting comments. The visual studio.net IDE is now legitimizing that practice by automatically beginning each new line of a multi-line comment with a star. I just find it annoying. I wonder what’s the point.
Other strange coding practices I don’t understand:
Using vi or emacs. I hesitate to criticize this outright because in theory having an all keyboard interface would be faster once you got past the very steep learning curve. But do the proponents of these systems realize how many shortcuts are available to users of modern windows-based text editors? I got to see a real seasoned unix guy using vi the other day. He’s a very fast typist besides. He looked very slow and clumsy using it.
Indenting with spaces instead of tabs. I’ve seen many editors offer the option of using spaces. Why? Tabs seem much smarter to me. The key is pressed once, both to insert the tab and then to delete it if necessary, so it’s easier. Most editors have tab width settings besides, so if someone really likes code indented far, they can choose to display tabs wider than I would need to. Tabs conform better to personal preference. Besides, it’s much easier to convert a file from being tab-indented to space-indented if desired. You can pretty much always indiscriminately search-and-replace in that direction, whereas multiple spaces can’t always be replaced by a tab in code.