Who decided indenting with spaces was a good idea?(blog.amwmedia.com)
blog.amwmedia.com
Who decided indenting with spaces was a good idea?
http://blog.amwmedia.com/post/115220544982/who-decided-indenting-with-spaces-was-a-good-idea
9 comments
The tab character has been around since 1963. I have so far never in my life had a problem with using "smart tabs"[1][2]. For my purposes (web development), I don't expect that this will ever happen.
I'd be interested to know a real-world, recent example where tabs could have been a problem for someone.
1. http://www.emacswiki.org/emacs/SmartTabs
2. http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_space...
I'd be interested to know a real-world, recent example where tabs could have been a problem for someone.
1. http://www.emacswiki.org/emacs/SmartTabs
2. http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_space...
I'm sure there ARE parsers and old terminals that may not understand tabs, but I don't plan to make decisions about how I write code based on the possibility of maybe, someday running into SOMETHING that doesn't like what I'm doing. Especially when switching my entire code base from tabs to spaces is as simple as a global find/replace.
Oh god. You might as well have posted, "Why do people use Mac instead of Windows?" in the year 2002.
People use spaces because they're a fixed width, not in spite of that fact. They allow you to know that your code will look exactly the same with any monospace font, which is especially important if you do things like lining up operators.
I personally use a hybrid: the entire line is indented with tabs. This tells you which block you're in.
Then, for alignment or anything else that isn't related to the entire block, I use spaces.
Many IDEs support this hybrid mode, including the IntelliJ family. It gives you the best of both worlds.
People use spaces because they're a fixed width, not in spite of that fact. They allow you to know that your code will look exactly the same with any monospace font, which is especially important if you do things like lining up operators.
I personally use a hybrid: the entire line is indented with tabs. This tells you which block you're in.
Then, for alignment or anything else that isn't related to the entire block, I use spaces.
Many IDEs support this hybrid mode, including the IntelliJ family. It gives you the best of both worlds.
Makes sense in a way I guess, but I would hate to work with you. I've now got to use some different text editor or install a plugin to alternate between white space characters?
It's not a problem working with others, since you can replicate this manually without much effort.
Let's say I have the following code:
Many IDEs and text editors will automatically detect indentation settings, and some of the popular ones (WebStorm, Netbeans, I think vim) also support hybrid indentation.
So it's only really a problem when someone uses a plain-text, Notepad-like text editor, but I haven't met a professional developer who does that in a long time.
Let's say I have the following code:
if (test1) {
if (test2) {
executeSomething({
"first" : "1st",
"second" : "2nd"
});
}
}
Here's the same code with spaces replaced by "S" and tabs replaced by "T": TifS(test1)S{
TTifS(test2)S{
TTTexecuteSomething({
TTTT"first"SS:S"1st",
TTTT"second"S:S"2nd"
TTT});
TT}
T}
You could set your IDE to use tabs, and then for fine-grained indentation (where I've lined up the property definitions in the object), you'd use spaces.Many IDEs and text editors will automatically detect indentation settings, and some of the popular ones (WebStorm, Netbeans, I think vim) also support hybrid indentation.
So it's only really a problem when someone uses a plain-text, Notepad-like text editor, but I haven't met a professional developer who does that in a long time.
TTifS(test2S&&
TTSSSStest3)S{
// ...
Show me an editor which can tell indentation from alignment at the beginning of the line. And moreover, which can tell it for a dozen of unrelated languages, like Perl, C, make, Erlang, XML and YAML.All IntelliJ products[1], vim[2], and emacs[3] support this. They call it "smart tabs". Sublime has a plugin that does something similar[4].
I don't have it installed and can't find documentation for it, but I believe NetBeans does this by default.
Again, this is something that usually happens naturally when you're indenting with tabs. Very few humans or programs are going to do alignment with tabs, even if they're indenting with them.
1. https://www.jetbrains.com/idea/help/code-style-java.html#d53...
2. http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_space...
3. http://www.emacswiki.org/emacs/SmartTabs
4. http://wbond.net/sublime_packages/alignment
I don't have it installed and can't find documentation for it, but I believe NetBeans does this by default.
Again, this is something that usually happens naturally when you're indenting with tabs. Very few humans or programs are going to do alignment with tabs, even if they're indenting with them.
1. https://www.jetbrains.com/idea/help/code-style-java.html#d53...
2. http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_space...
3. http://www.emacswiki.org/emacs/SmartTabs
4. http://wbond.net/sublime_packages/alignment
OK, and now explain me why none of these work correctly with all the mentioned languages.
They work fine with Perl, C, XML, and YAML. I wouldn't know about Erlang, but I'd imagine they work with that, too.
It seems as though you have an idea in your head that you're unwilling to research, and when I present you with information, you're unwilling to accept that you could be wrong.
It seems as though you have an idea in your head that you're unwilling to research, and when I present you with information, you're unwilling to accept that you could be wrong.
> They work fine with Perl, C, XML, and YAML.
Or do they? Either they are language agnostic or they are not. If they are language-independent, they can't work properly, since indentation and alignment are syntax-specific (that is, need some information extracted from syntax). If they are language-specific, they can't work with all the languages I happen to need, which may include some DSLs rarely used by programmers and some languages defined by myself. I see no other option.
I have checked plugin for Vim; it doesn't work as you advertise. It either puts only spaces or only tabs at the beginning of the line, depending on expandtab setting. I assume from your comment that others work as well as this one.
Or do they? Either they are language agnostic or they are not. If they are language-independent, they can't work properly, since indentation and alignment are syntax-specific (that is, need some information extracted from syntax). If they are language-specific, they can't work with all the languages I happen to need, which may include some DSLs rarely used by programmers and some languages defined by myself. I see no other option.
I have checked plugin for Vim; it doesn't work as you advertise. It either puts only spaces or only tabs at the beginning of the line, depending on expandtab setting. I assume from your comment that others work as well as this one.
> tabs actually use less space on disk as only one character is stored instead of 2, 4 or 8.
If I didn't have the ability to store 1,000,000,000,000 of them, I'd care greatly. To be honest source code size isn't even in the ballpark of concerns I have. Intermediate bin files (e.g. obj files) are far larger and problematic for source control and sending source to someone (e.g. several meg a piece rather than a couple of hundred KB).
As for an answer to your question: Spaces are an exact width. Tabs change widths. Therefore for precision and reproducibility spaces are a better choice across all platforms.
Many IDEs support inserting a preset number of spaces when you tab anyway, so the problem is invisible to you.
If I didn't have the ability to store 1,000,000,000,000 of them, I'd care greatly. To be honest source code size isn't even in the ballpark of concerns I have. Intermediate bin files (e.g. obj files) are far larger and problematic for source control and sending source to someone (e.g. several meg a piece rather than a couple of hundred KB).
As for an answer to your question: Spaces are an exact width. Tabs change widths. Therefore for precision and reproducibility spaces are a better choice across all platforms.
Many IDEs support inserting a preset number of spaces when you tab anyway, so the problem is invisible to you.
Code size does matter for websites and web apps, and for high-traffic sites, the difference between 1 byte and 4 bytes is significant.
That said, if you've gotten to a point where you have high traffic, you've had lots of time to implement something that optimizes your assets anyway.
That said, if you've gotten to a point where you have high traffic, you've had lots of time to implement something that optimizes your assets anyway.
Because sometimes you must use spaces, because you are indenting a continuation line that should be indented to an exact spot with respect to the previous line (you're in the middle of an expression, you want to be at the start of an open parenthesis, etc).
Surely the suggestion in that case is not to carefully insert tab characters to the same indentation of the previous line, and then spaces for the rest, so that you have some tabs and some spaces on the continued line? Anything else fails if the tabs are set as "developer preference" on display, but that tabs + spaces on one line is incredibly fiddly.
Surely the suggestion in that case is not to carefully insert tab characters to the same indentation of the previous line, and then spaces for the rest, so that you have some tabs and some spaces on the continued line? Anything else fails if the tabs are set as "developer preference" on display, but that tabs + spaces on one line is incredibly fiddly.
yeah, I would wonder why your continuation line has to line up perfectly with the previous one. When you start laying your code out so that everything is perfectly aligned to everything else, it just leads to headaches and heartbreaks when other developers don't share your passion for perfectly manicured code. :-)
I dislike ever seeing this. Sounds too OCD
Even though I prefer to use tab characters at home it would be much better if a single tab character could indent the code to the appropriate level. So a tab character means indent the code to where appropriate based on some predefined rules. Granted this is only possible for some languages and not others, and it would be much nicer even when using a non-flat file for code.
The guy that had to use punched cards to enter code that would be printed to paper.
http://computers.mcbx.netne.net/media/pcards/k_cobol_cyf.jpg
http://computers.mcbx.netne.net/media/pcards/k_cobol_cyf.jpg
TABS + 1TBS = Pabst Blue Ribbon MF!
Because you can move the cursor vertically and be in the correct column.
Use an IDE that's smart enough to do it for you
A lot of mysteries about why people don't use clearly-superior technological solutions are solved by understanding that ubiquity is a feature, in many cases the most important feature. I don't use vim because it's the best text editor; I use it because I can be reasonably sure every single UNIX-like system I ever log into will have it, and once it's in my fingers from having to learn it on a remote server, I might as well use it for daily programming. I don't use HTTP because it's an efficient protocol; I use it because every single device, library, and language speaks it. I didn't write Gumbo [1] in C because I like the language; I did it because every modern language can bind to C libraries, and so this lets a maximum number of people use it.
[1] https://github.com/google/gumbo-parser