by drewrv · 10y ago · 0 comments
Also, plenty of geniuses use tabs :) the Linux kernel included. It obviously has no relation.
(Seriously though, tabs are a matter of accessibility. https://leclan.ch/tabs)
But what happens in practice is that the file ends up with a mish-mash of tabs and spaces throughout and the file is only legible if you set your tab stop to a specific setting, and sometimes not even then because different authors have used different tab stops for both indentation and alignment. At which point the tabs buy you nothing.
So just use spaces and be done with it. Or go fmt. :-)
Here's some Befunge interpreters in a few different languages: https://github.com/serprex/Befunge
There is no other way to do tabs. Anything else is simply wrong and grounds for execu... a stern talking-to.
Simply use indentation in the places where you might be tempted to start lining up columns.
It's really easy to use an alignment-free style. A good way to get in the habit is to code in a proportional font instead of monospaced. By doing that, you won't be able to use column alignment, and you'll naturally gravitate toward using indentation to represent the block structure of your code.
As someone who tabs, 4 is a very common standard, and consistency has never been a problem.
(I use spaces only because I try to follow common coding styles, like PEP 8, but I never gave it enough thought)
Aligning within a line can and should be done with spaces. There's good reasons against alignment in such cases -- for example, it creates git blame/git diff noise when reformatting due to having to update alignment on a bunch of other lines just because you introduced a variable one character longer than the others. Irrelevant, though; such alignment is perfectly fine to do with spaces in a context where you indent with tabs.
The other type of alignment is beginning-of-line alignment, which is indeed not doable with spaces. Some people recommend doing such alignment with spaces despite the tab indent (cf. http://dmitryfrank.com/articles/indent_with_tabs_align_with_...). It's a valid argument but I feel it's too much of an aberration to be taken seriously.
I personally find such alignment generally repulsive anyway. Take a look at the following code and tell me which method looks better:
Too many times have I seen such function calls where the space between the parenthese and the soft wrap leaves <10 characters to work with. And here we go with one small argument per line, every argument preceded by 70+ spaces. I know programmers who could fit video games in the bytes used for just a single function call like that.
But I'm with you: that kind of column alignment is harmful to maintainability, and I find it much less readable too.
Some time ago I posted a few examples of column alignment gone bad, from the Servo source code:
https://news.ycombinator.com/item?id=9469713
and also discussed alignment here:
https://news.ycombinator.com/item?id=9469713
Once you give up column alignment, there's no longer any real reason to prefer spaces, and you can gain the benefits of using tabs. As a side benefit, when you give up alignment, your code becomes just as readable in a proportional font as a monospaced font.
More details in my previous comments linked above, so I won't rehash them here. :-)
If you're working with git on a non-whitespace-sensitive language, and this annoys you, you can use the --ignore-space-change option to avoid this.
That seems like a strawman to me. I would go with something like:
function() {
nested_code() {
some_very_long_function_call(
long_argument_one, long_argument_two,
long_argument_three, long_argument_four,
);
}
}The second is better looking. I'd rather maintain the second.
But...
The first is easier to read. The shape of the code is enough for me to parse without effort. In the second, I have to "walk myself" through the code, even for this little example. I feel the effort required as soon as I have to start looking for the embedded commas.
So I usually choose something like the first, since time spent typing matters less than time spent thinking.
I maintain that if tabs are permitted, so are other ASCII control codes, like vertical tab, form feed (which is actually used in GNU code), and bell.
int foo(void)
{
<TAB>/* <BEL><BEL><BEL> This bit is really important. */
<TAB>...
}
<VT>
int blah(void)
{
<TAB>...
}
<EOT>
<EM>
:-)The GNU coding standards request form-feed (\f or ^L) to separate code into logical pages.
https://www.gnu.org/prep/standards/standards.html#index-cont...
But I like your sense of humor, so you definitely earned an upvote from me - a flaming tab advocate!
(And I learned to program on a ASR33 Teletype - so I do miss those old control codes...)
The support in editors is abysmal and doesn't work out of the box correctly for tabs (e.g. invisible whitespace).
I've never seen an argument for spaces that would hold iff all editors would have sane defaults for programmers. Of course, it's also bad that some programmers can't configure their tools correctly, but that is a complete different issue.
The best of both worlds would be "tabs for indentation, spaces for alignment" but as it is now, you only need one programmer with wrong settings to screw that up, so that's why most projects have settled on the most conservative setting.
If you do that, all of these issues go away. You can use tabs or spaces for indentation, and it won't affect your formatting. You can reformat the code to a different number of spaces, or switch from spaces to tabs or vice versa, and your code will still be perfectly formatted.
A good way to learn and practice this style is to switch your editor to a proportional font. Now you won't be able to use column alignment, and without even working at it you'll naturally start to explore an alignment-free style.
I've had many programmers react in shock when they see I write code in a proportional font, but when you don't use alignment it stops mattering what font you use.
With tabs you need to configure each and every tool you use to use the right indent (2? 4? 8?), with spaces, every tool just works, and copy/pasting a section of code to or from an issue or an e-mail or a chat tool just works.
It is a matter of code typography. When more than one developer is working on a code base, it helps if every one sees the same outline, because with varying amounts of indenting one persons preference aligns all parameters in a long important method call, whilst any other indenting breaks (part of) that format — code may look fine for one person, but jumbled for another with a different indent preference.
With editor support better than ever, using spaces isn't something you think about when coding; you just hit tab to indent and it inserts the number of spaces configured.
I like Python's PEP 8 in that respect. The language itself (and the syntax checking tools such as pyflakes) simply states the sensible default you aught to be using.
You mean like those times I would have to configure my editor so it inserts the exact amount of spaces required by the project I'm working on, for the project maintainers prefer 4-width to 2-width or 8-width? :)
You talk about typography but this is exactly what I underline in my article: Your preference is not everybody else's and I personally find 2-space code absolutely unreadable... while some companies adopt it as their internal codestyle.
My eyesight has been deteriorating for the past 10 years and I've had to increase my font and zoom sizes as well as line spacing every now and then. Compact 2-space code truly is a strain on the eye for me. If you're using tabs, you don't have to care about my eyesight, just like you don't care about my font size.
In short, the real issue with tabs is that you can't reliably use them for column alignment. But many of us have concluded that column alignment is a harmful practice, preferring indentation instead to show the structure of our code.
And once you give up column alignment, you can use tabs for indentation, and it just doesn't matter what tab size the person reading your code prefers. It will read just the same in any tab size and any font, even proportional fonts.
It's really quite liberating to stop using column alignment. :-)
It's impossible to use anything but spaces in LISP without going mad, and the editors like emacs do a fantastic job formatting the s-expressions. So spaces are very superior to tabs for some languages.
For languages with a syntax similar to C, it doesn't matter, the rant was taken out of context, and the rest is history.
Whatever you use, make tabs and spaces visibles in your editor and never, ever, mix them up for indentation.
I suspect that it isn't much of an issue in practice for a few reasons:
1) I'd wager that most projects that have a hard 80-column limit also forbid tabs.
2) If a project does use tabs and has a hard line length limit, it can simply say that that limit is interpreted using a certain tab size (e.g. the most common tab size is probably 4 spaces).
3) In my own code, as I've mentioned probably too many times in this thread :-) I don't use column alignment, which is one of the main causes of excessive line length. Because I use indentation for multiline expressions, my lines of code tend to be a lot shorter than they would be with column-aligned expressions.
Apparently nested JS runs faster with spaces.
And seeing as 80 characters is still the normal line limit, because of window splitting, it does happen quite often.
If you stop using alignment and use only indentation for your multiline statements, these issues go away. Your code will be just as readable with any tab size, and even in a proportional font. And your line lengths get much shorter in the process.
For specific examples, see the other comments in this thread from scrollaway and myself, in particular the Servo source code I linked to.
I remember when I got into coding Runescape autoclick bots when I was 14, in an arcane Delphi editor / standard library called SCAR, it was the insane convention to not use any indenting at all. Indeed you had to manually hit the spacebar again and again to get some proper indenting.
Also, the spacebar key on my keyboard was noisy.
Not hard to find very smart people with very poor coding standards.
Attack(0) would attack yourself in wilderness, leaving bystanders confused.
You can easily and losslessly do it the other way around, though, which leads me to do exactly what you say when working on a space-indented project: I code with tabs, I convert before committing. It's usually easier than dealing with spaces.
A business-basic style language i work with (second time i've talked about it in a few days... it's weird) saves it's files in a strange not-compiled-but-not-plaintext format that only it can read. That means you can't use your VCS of choice, you can't use your favorite editor, you can't even grep through the codebase to find where a variable name is used.
Technically you could write something to get it working in a more "normal" editor, but that is a path I don't want to run down.
Ignoring encoding, text is about as accessible as it gets. You can always layer more tooling on top of it, but you can't take it away from a non-text representation easily.
Personally I like the way that the go team handles it. Source files are "plaintext" (again, ignoring encodings for the sake of discussion), but there is one (and only one) canonical format for the layout of the code, and a tool which will apply it.
Then like you said, you can have IDEs which can layer more visual representations on top of that if needed, and there is a chance that some people could program without actually seeing the "plaintext" source code.
If spaces/tabs were just about nesting code blocks then this would all be a no-brainer, but vertical alignment can convey much more information than that (for example, splitting statements into semantically equivalent columns).
I used to do this before I switched from vi to vim. I used 2-space indents to save wear and tear on my thumb.
I've never met a programmer that didn't have some view of code style. Even the really clever ones consider their code to be a form of art, so what you use to write it does matter. It's all pretentious, but I actually thought it was a very accurate portrayal of the trivial things that programmers make a big deal out of.
Besides, why people don't use linters?
It's a comedy, that makes fun of the stuff happening in the Silicon Valley by strongly exaggerating it.
On a side note, geniuses are know to have unusual quirks.