4 ms·
I'm not sure what your complaint is here. With whitespace sensitivity, "oops, I missed a brace" and "oops, I missed a tab" is exactly the same. Your compiler/ID
by thinkpad20 12y ago
I'm not sure what your complaint is here. With whitespace sensitivity, "oops, I missed a brace" and "oops, I missed a tab" is exactly the same. Your compiler/IDE would catch it, just as it would any other syntax error. The difference (arguably) is that it's easier to spot (because that's how humans read code).
I would argue that whitespace sensitivity makes those kinds of errors less likely, not more. Curly braces everywhere lead to a lot of visual noise, and can obscure what the code is doing. Consider the classic C syntax error:
if (foo > bar)
printf("Hey!\n");
return foo;
return bar;
With whitespace sensitivity, this would do what you think it would. With curly braces, it's misleading.
- ufo 12y agoWhitespace sensitivity also introduces some similar problems. For example, if the printf is indented with spaces and the return foo is indented with tabs, the return will be put outside the if, even though it looks like its inside. TBH, the real problem with C is not the braces - its that braces are optional.
- meowface 12y ago>For example, if the printf is indented with spaces and the return foo is indented with tabs, the return will be put outside the if, even though it looks like its inside. Python 3 deals with this by throwing a warning about inconsistent use of tabs and spaces before it even finishes parsing the file (so basically before runtime). There's no reason why any other language can't do the same.
- deleted 12y ago[deleted]
- rdtsc 12y agoI think tabs vs spaces problem is silly and nobody should be using tabs. Editor should be showing tabs in red and asking the user to clean them up.
- WildUtah 12y agoI switched from tabs to spaces about a decade ago and I've never regretted it. I seldom find files written by crazy people who think 8 spaces is a viable tab width anymore so I can pretty much adjust to whatever nice 2 space or wasteful 4 space width the original file authors used. Back in the 1970s, I chose tabs to save bytes in my text files. Today I feel like I can afford the extravagance.
- ANTSANTS 12y agoI think the tabs vs spaces problem is silly and nobody should be using spaces[1]. Compilers should treat leading spaces as a syntax error. Clearly we both can't be pleased. ;) [1] Except in Lisp.
- Someone 12y agoEvery social problem has a simple, rational solution: forbid (and strongly enforce it) anybody making, owning, or talking about, any of the following: - editors that allow one to set tab width different from 1. - editors, compilers, and OSes that distinguish tabs from spaces in any way (display of invisible characters, search). - revision control systems that do not randomly replace spaces by tabs and vice versa in all text files.
- bnolsen 12y agoIf you used our coding style (haskell-ish) you would have no problems with tabs. Keep stuff logically towards the left to make quick scanning easier.
- binarycrusader 12y agoMost languages that are whitespace sensitive don't actually allow you to mix indentation. In fact, Python 2 will give you an error saying that a particular line doesn't match indentation level if it's a different number of spaces and 3 will give you a warning (and since warnings can be made into errors...).
- claudius 12y ago> With whitespace sensitivity, "oops, I missed a brace" and "oops, I missed a tab" is exactly the same. No. There are two braces per block and as long as you are consistent and always use braces even for single-statement if(){}, you need to miss two braces for equivalence with missing one tab. You also get the benefit that the editor can trivially re-indent your code without actually changing its meaning.