4 ms·
Because spaces are rendered the same everywhere. Suppose I write this code, indenting using spaces. im_a_long_method(argument_no_1, se
by bjourne 12y ago
Because spaces are rendered the same everywhere. Suppose I write this code, indenting using spaces.
im_a_long_method(argument_no_1,
set_indentation_true(...),
no_string_cutoff,
whatever)
Now suppose I used tabs to indent and my editors tab width is 4 spaces while your is 8 spaces, then the above would look like:
im_a_long_method(argument_no_1,
set_indentation_true(...),
no_string_cutoff,
whatever)
Since not every editor agrees on how wide a tab character is, you get crappy alignments. Therefore use spaces.
- dragonwriter 12y ago> Because spaces are rendered the same everywhere. Suppose I write this code, indenting using spaces. Then it'll look wrong in a proportional font; indenting and aligning with non-indented text are different things. Either spaces or tabs indent consistently when used consistently in a source file. Alignment cannot be acheived consistently (with spaces or tabs) unless you also assume a monospaced font, or (with tabs) have elastic tabstops.
- dysfunction 12y ago...and maybe that's why most popular coding fonts are monospaced?
- dragonwriter 12y ago> ...and maybe that's why most popular coding fonts are monospaced? Yes, the desire to use alignment without something like elastic tabstops being widespread is the limitation which prevents wide adoption of otherwise-superior proportional fonts in coding.
- J_Darnley 12y agoI really don't get the point of tabs for visual layout in any kind of document be it plain text, source code, or a word processor document. They never seemed to work right for me. I remember using the tab key to enter tabs back in school to make something like an informal, 2-or3-column table (or whatever I was actually doing). This would have been in Word. Things would line up pretty until I wanted to change some text. If I made it longer I would need to add another tab because the tab had shrunk to nothing. If I made it shorter the tab would jump into the previous section and no longer line up with the other lines. As far as I can see, the same will happen with this source example if it were using tabs and a proportional font.
- dragonwriter 12y agoElastic tabstops are so named because the width adjusts based on the content, avoiding that problem. http://nickgravgaard.com/elastictabstops/ http://nickgravgaard.com/elastictabstops/
- lutusp 12y ago> Then it'll look wrong in a proportional font Programmers don't use proportional fonts. Source code maintenance is hard enough without asking for trouble.
- iLoch 12y agoThis is a great argument, thanks.