+1  A: 

When I last looked at Eclipse (some time ago now!) it allowed you to choose any installed font to work in. Not so sure whether it supported the notion of indenting using tab stops.

It looked cool, but the code was definitely harder to read...


I have the C++ Programming Language at home, but for those who don't have access to it, can you post a picture or scan of a code snip from that book? I thought it used mono-spaced fonts, like Courier.

Thomas Owens
+10  A: 

I'd still like to see a popular editor or IDE implement elastic tabstops.

Sören Kuklau
Wow! I've never seen this before and I already want it on every IDE I use.
+4  A: 

i expected you'll get down-modded and picked on for that suggestion, but there's some real sense to the idea.

The main advantage of the traditional 'non-proportional' font requirement in code editors is to ease the burden of performing code formatting.

But with all of the interactive automatic formatting that occurs in modern IDE's, it's really possible that a proportional font could improve the readability of the code (rather than hampering it, as i'm sure many purists would expect).

A character called Roedy Green (famous for his 'how to write unmaintainable code' articles) wrote about a theoretical editor/language, based on Java and called Bali. It didn't include non-proportional fonts exactly, but it did include the idea of having non-uniform font-sizes.

Also, this short Joel Spolsky post posts to a solution, elastic tab stops (as mentioned by another commentor) that would help with the support of non-proportional (and variable sized) fonts.

Leon Bambrick
+1  A: 

Soeren: That's kind of neat, IMO. But do people really line comments up like that? For my end of line comments, I always use a single space then // or /* or equivalent, depending on language I'm using. I never try to line up declarations or comments or anything, and the only place I've ever seen that is in textbooks.

Thomas Owens
+2  A: 

@Thomas Owens

But do people really line comments up like that? ... I never try to line up declarations or comments or anything, and the only place I've ever seen that is in textbooks.

Yes people do line up comments and declarations and all sorts of things. Consistently well formatted code is easier to read and code that is easier to read is easier to maintain.

Brian Ensink

@Brian Ensink: I don't find code formatted like that easier to read.

int var1 = 1 //Comment
int longerVar = 2 //Comment
int anotherVar = 4 //Command


int var2       = 1 //Comment
int longerVar  = 2 //Comment
int anotherVar = 4 //Comment

I find the first lines easier to read than the second lines, personally.

Thomas Owens
+2  A: 


It's not the readability that hurts in the second case but the maintainability! If it was as easy to maintain fancy formatting as simple formatting, I'd totally be with you.

Jeff Atwood
+3  A: 

@Thomas Owens

I don't find code formatted like that easier to read.

That's fine, it is just a personal preference and we can disagree. Format it the way you think is best and I'll respect it. I frequently ask myself 'how should I format this or that thing?' My answer is always to format it to improve readability, which I admit can be subjective.

Regarding your sample, I just like having that nicely aligned column on the right hand side, its sort of a quick "index" into the code on the left. Having said that, I would probably avoid commenting every line like that anyway because the code itself shouldn't need that much explanation. And if it does I tend to write a paragraph above the code.

But consider this example from the original poster. Its easier to spot the comments in the second one in my opinion.

for (size-type i = 0; i<v.size(); i++) { // rehash:
    size-type ii = has(v[i].key)%b.size9); // hash
    v[i].next = b[ii]; // link
    b[ii] = &v[i];

for (size-type i = 0; i<v.size(); i++) {     // rehash:
    size-type ii = has(v[i].key)%b.size9);   // hash
    v[i].next = b[ii];                       // link
    b[ii] = &v[i];
Brian Ensink
Great example - the '//link' comment gets lost in the first example. A casual scan of the code might miss it completely.
+2  A: 

Thinking with Style suggests to use your favorite text-manipulation software like Word or Writer. Create your programme code in rich XML and extract the compiler-relevant sections with XSLT. The "Office" software will provide all advanced text-manipulation and formatting features.

Andreas Scherer

The major problem with proportional fonts is they destroy the vertical alignment of the code and this is a fairly major loss when it comes to writing code.

The vertical alignment makes it possible to manipulate rectangular blocks of code that span multiple lines by allowing block operations like cut, copy, paste, delete and indent, unindent etc to be easily performed.

As an example consider this snippet of code:

a1 = a111;
B2 = aaaa;
c3 = AAAA;
w4 = wwWW;
W4 = WWWW;

In a mono-spaced font the = and the ; all line up.

Now if this text is loded into Word and display using a proportional font the text effectively turns into this:

NOTE: Extra white space added to show how the = and ; no longer line up:

a1 = a1 1 1;
B2  = aaaa;
c3 = A A A A;
w4 = w w W  W;
W4  = W W W  W;

With the vertical alignment gone those nice blocks of code effectively disappear.

Also because the cursor is no longer guaranteed to move vertically (i.e. the column number is not always constant from one line to the next) it makes it more difficult to write throw away macro scripts designed to manipulated similar looking lines.

In my question I state that "I want to set tab stops for my indents and lining up function signatures and rows of assignment statements." A proportional editor can be (optionally) smart about converting to/from fixed space upon copy/paste and cursor navigation(down will always stay on same column)
Mark Cidade
In the sample pseudo code I gave there are no tabs only and a single white space, so no amount of tabs stops are going to make the text line up on the screeen. The location of the ; will vary from line to line and at least for me and the way I code, that is a show stopper.
The "=" and ";" characters no longer line up: this is true, but I think it's not a good example. Realistically, how often do you have many rows of assignment statements with all the variable names having the same length, and all the rest of the statements also having the same length? If they have differing lengths, and you want the "=" characters to line up, you can use a tab, as he desires, and everything works anyway. (And if you're spending time lining up your ";" line terminators...well, your time is probably better spent elsewhere.)
+1  A: 

I wonder why nobody actually answers your question, and why the accepted answer doesn't really have anything to do with your question. But anyway...

a proportional font IDE

In Eclipse you can cchoose any font on your system.

set tab stops for my indents

In Eclipse you can configure the automatic indentation, including setting it to "tabs only".

lining up function signatures and rows of assignment statements

In Eclipse, automatic indentation does that.

which could be specified in points instead of fixed character positions.

Sorry, I don't think Eclipse can help you there. But it is open source. ;-)

bold and italics

Eclipse has that.

Various font sizes and even style sheets would be cool

I think Eclipse only uses one font and font-size for each file type (for example Java source file), but you can have different "style sheets" for different file types.

The accepted answer is the closest that comes to what I want ("Does anyone know the best way to start building one?"). I don't want to just insert fixed-length tabs. I want variable-length tabs on a per-line basis like in a word processor. I don't want the IDE to indent for me—my indents are complex
Mark Cidade
Ah. :)I didn't get that from your image, it looks just like plain old indentation to me.

Folks are all complaining about comments not lining up.

Seems to me that there's a very simple solution: Define the unit space as the widest character in the font. Now, proportionally space all characters except the space. the space takes up as much room so as to line up the next character where it would be if all preceeding characters on the line were the widest in the font.




would line up the "Foo", with the space after the "i" being much wider than after the "x".

So call it elastic spaces. rather than tab-stops.

If you're a smart editor, treat comments specially, but that's just gravy