For example:
function_call(really_really_really_really_really_argument1,
really_really_really_really_really_argument2)
Say that this is supposed to be at one indent level. The beginning of both of those lines should contain only one tab, and the spacing that positions the second argument from the indent should be only spaces: <tab>function_call(really_really_really_really_really_argument1,
<tab>SSSSSSSSSSSSSSreally_really_really_really_really_argument2)
If the text looked like above (each 'S' is a space), then one's editor could easily change whether or not a <tab> was displayed as 8 spaces or as 4 spaces, and the display wouldn't be affected. Many editors, however, consider all spacing at the start of the line to be indentation. If you were using one of those editors with tabs set to (e.g.) 4 spaces, the code might look something like this: <tab>function_call(really_really_really_really_really_argument1,
<tab><tab><tab><tab>SSreally_really_really_really_really_argument2)
Now the code only looks the way it was meant to look if you have you <tab> = X spaces value set to 4. If you set it to something else, the code looks like a mess. function(
really_really_really_really_really_long_argument1,
really_really_really_really_really_long_argument2,
really_really_really_really_really_long_argument3);I wish the pioneers of programming languages would have had the foresight to provide an automatic formatting tool and standardize on a canonical layout. So much time and effort would have been saved.
Further, I think code guideline documents and discussions without an accompanying config file for astyle or clang-format are pretty useless.
I'm not a fan of Python's significant whitespace or PEP-8 in the first place. It puts too much emphasis on aesthetics at the cost of practicality. Writing a parser or any tooling for that is just a pain in the ass. I do use Python occasionally but for very different reasons than aesthetics.
What? If your editor can't tell the difference between you hitting the tab key versus the spacebar, it's a bug in your editor.
Smart tabs - the idea you're talking about - is well-supported in just about every major editor.
* Use different tools - IDE, command line, version control tool, code review tool, e-mail client.
* Have code that follows with different conventions - because you participate in several projects, or because you've imported third party code that follows a different convention, or because the code is written in different languages.
* Have co-workers with different opinions about what tab width should be set to.
Personally I don't think there's that much value in vertically aligning things, except in lookup tables. Usually it's a sign you've adopted line-length rules that don't reflect modern monitor sizes, or that your methods have too many parameters. But some people seem to think it's valuable.
If you use spaces, you can format code, knowing it will look right on other people's machines. Perhaps a sufficiently organised bunch of programmers could edit a large code base such that it viewed fine with 2,4 or 8 character tabs, but is it worth the pain?
I keep my programs less than 80 character wide for accessibility purposes but if I use tabs then the width is unpredictable.
Also, spaces are universal and trivial whereas the TAB button in many editors has strange behavior.
def doSomething( parameter1
, parameter2
, parameter3
):
pass
How would you make all the punctuation line up using tabs? def do_something(parameter_1,
parameter_2,
parameter_3):
pass def do_something(
param1, param2,
param3, param4
):
...
It's not that hard. Alignment is generally harmful - it's a maintenance burden which adds whitespace noise on diffs, which means more noise in code reviews. Not to mention how atrociously ugly it is when long variables/method names lead to 5+ lines with 60+ characters of indent for a single variable name per line.2. Those options are not perfect, they don't always work as expected
3. Those options are not turned on by default (because that would be INSANE)
4. Git's not the only VCS, much as I wish it were
5. Github's not the only Git web UI; that option is not available everywhere.
It's not a "solved problem". It's an artificial problem, that gets solved when you start consistently stripping trailing whitespaces on save and not realigning everything all the time.
This is mostly solved via coding standards. If there are no coding standards people will "refactor" the coding style when they touch various pieces of code. If people were following a consistent style, then the alignment wouldn't be changing all of the time.
Although I strongly agree with the trailing whitespace sentiment. The most egregious offender that I've found is Eclipse putting trailing spaces on blank lines to bring them to the indent level of the non-blank lines. Ugh.
enum {
NORMAL = 1
ABNORMAL = 2
IRREGULAR = 3
}
Now if you're writing like this, what happens when you introduce "EXCEPTIONAL = 4"? You change 3 other unrelated lines. This is something that alignment causes, regardless of "coding standards". Hell, gofmt does that... It looks pretty (to some extent - with long names and lots of members it gets unreadable), but creates so much noise.But then tabs vs. spaces isn't an issue.