4 ms·
The problem with that is that it doesn't work when you have code (and comments) formatted in neat columns. Since plain text doesn't have any portable way to han
by robert_tweed 12y ago
The problem with that is that it doesn't work when you have code (and comments) formatted in neat columns. Since plain text doesn't have any portable way to handle tabstops, everything has to be padded out (after the initial indent) with extra spaces. Characters must have equal widths or nothing lines up properly.
This is pretty common in long repetitious declaration blocks, at least when the code is written by someone that cares about formatting. It vastly improves readability. Example:
int some_variable = 100; // Foo
float another_variable = 1000.0; // Bar
The gofmt tool actually does this kind of column formatting automatically.
- morsch 12y agoKind of strikes me as something the editor could do ad-hoc. Maybe the tab character could return to let programmers tell the editor to align the adjoining lines according to the tabs. Would work well at least in your example.
- seanmcdirmid 12y agoElastic tab stops: http://nickgravgaard.com/elastictabstops/ http://nickgravgaard.com/elastictabstops/ You could also pad your spaces in the editor so that they align along a global axis. This does fix your code to a particular editor, however.
- morsch 12y agoExactly what I was thinking of, brilliant!
- robert_tweed 12y agoYeah this is nice. All we need now is for this to be supported in all major text editors and we're set! The only possible issue (not sure how it's handled, can't remember if/how gofmt handles it either) is when sometimes you actually want something to be misaligned because the width is so far out of the norm, e.g: int const1 = 10; // There's lots of space here for a long comment int const2 = 5; // Here too, unless the tabs get moved too far right float const3 = ( const1 * 123.45 ) / MAGIC_CONSTANT; // Not here. Normally when this happens I try to regroup the code so that "plain" constants are together and long formulas are in another group, but sometimes the order is important for some reason or doesn't make logical sense to regroup items, so the formatting has to suffer a bit.
- morsch 12y agoAs long as you rely on the tab character to signal the programmer's intent on inserting an elastic tabstop, that's not an issue. In this case, insert a \t in front of the comments on the first two, but not the third line. All three lines could have \t's in front of the equals character so align on it. The other nice thing is that it degraces quite gracefully in non-supporting editors.
- seanmcdirmid 12y ago> The problem with that is that it doesn't work when you have code (and comments) formatted in neat columns. I mentioned ascii art as something that fixed-width type writer fonts are optimized for.