3 ms·
Not all editors are smart about tabs and spaces, and when the two start to mix things get really funky if everyone doesn't have the same "1 tab = x spaces" valu
by pyre 10y ago
Not all editors are smart about tabs and spaces, and when the two start to mix things get really funky if everyone doesn't have the same "1 tab = x spaces" value set on their editor.
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.
- adontz 10y agoYour point is valid, that's why I write function( really_really_really_really_really_long_argument1, really_really_really_really_really_long_argument2, really_really_really_really_really_long_argument3);
- pyre 10y agoRight, not now you're dictating coding style to work around the warts associated with using tabs. If you use spaces there are no such issues because spaces don't change widths between editors.
- adontz 10y agoTo be honest, no, because my formatting will not be broken after refactoring changing function name length.
- exDM69 10y agoThe kind of formatting you suggest - aligning with spaces to get beautiful indenting - is a royal pain in the ass to edit. You change the function name to something a few characters shorter and now you have to change all the lines. It's prettier than the alternative, though (I still don't use it). 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.
- pyre 10y agoThat particular form of formatting is part of Python's PEP-8, which has tooling around it. Maybe not all editors have something built it, though.
- exDM69 10y agoEditor is one thing and most fully featured editors probably have an indent mode like this. Then there's all the other tools, like diff/merge tools, automatic refactoring scripts, etc which don't work as well. 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.
- collyw 10y agoI disagree. I moved form Perl to Python and disliked the whitespace to begin with. It does solve a couple of problems - it forces inexperienced coders to indent properly (I had one colleague who didn't when she used Perl). It also solves the missing brace problem when moving blocks of code around, which for me makes it worthwhile. It does make moving blocks around and commenting sections out a bit more effort, but way less effort than trying to work out where the brace has gone.
- groovy2shoes 10y ago
- alexwebb2 10y ago> Many editors, however, consider all spacing at the start of the line to be indentation. 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.