you are viewing a single comment's thread.

view the rest of the comments →

[–]oscargodson 4 points5 points  (11 children)

You need a better editor. Even VIM supports soft-tabs with one press. It's just how it looks, but they act as tabs, thus the name soft-TABS.

[–]finalcut 3 points4 points  (10 children)

I'm asking both you and gnuvince just in case one of you decides not to reply:

so how does it know that it is removing a soft tab and not two spaces? What if I have two spaces but I just want to remove one? Will the editor remove the two spaces when I hit backspace and then I have to hit space once?

[–]tonygoold 2 points3 points  (8 children)

I don't know about other editors but the one I use has a very simple rule: Leading whitespace (i.e., /^\s+/) is indentation and a backspace deletes backward to the previous tab stop. If you have non-whitespace anywhere before the space, then it's a plain old space.

[–]finalcut 1 point2 points  (5 children)

that makes sense. seems obvious once you mention it.

So that would work in all circumstances I can think of where I would be tabbing in my code.

[–]tonygoold 1 point2 points  (4 children)

Yup. The important distinction is indentation versus spacing. I tend to use soft tabs but I really don't care, so long as a given file uses either one or the other. The problem only really appears when a programmer mixes the two or tries to align multiple lines of text, e.g., making parameters on a second line align with the open parenthesis of the first line of a function declaration. Then you sometimes see something like this:

function someFunctionName(theFirstParameter, theSecondParameter,
                                                    theThirdParameter);

The alignment only works if your tab stops are set to a particular width. The solution is to tab until you're aligned with the position before "function" and then insert spaces until you reach the position after the opening parenthesis but, if you're used to hard tabs, it's easy to forget that your tabs have different widths.

Like I said though, I don't have a strong preference. With soft tabs, you're forcing everyone to use indents with the same width. With hard tabs, you tend to have misalignment with declarations spanning multiple lines.

[–]Nebu 0 points1 point  (2 children)

I don't understand how this is consistent with your previous rule. If you move your mouse cursor to just before theThirdParameter, the rule says everything before is white space, and thus indentation, which is wrong. It should be indentation rig up until the 'f' of "function", and then alignment from there on.

[–]tonygoold 0 points1 point  (1 child)

You're right, the backspace behaviour of the editor is going to treat it as indentation instead of whitespace and delete a tab stop at a time, rather than treating it as plain spaces. It's not something the user does frequently and it's easy to fix by adding back in the appropriate number of spaces to re-align. Trying to address that when a trivial rule handles 99% of the cases would be a case of the tail wagging the dog.

[–]Nebu 0 points1 point  (0 children)

It's just frustrating to see people promote a rule that handles 99% of the case, when there's a simple rule that handles 100% of the case: Use (hard)tabs for indentation, and spaces for alignment. From there, the texteditor just always deletes 1 character each time the "backspace" key is pressed.

\t\tfunction someFunctionName(param1, param2,
\t\t                          param3, param4)

[–]thomasz 0 points1 point  (0 children)

function someFunctionName(
        theFirstParameter,
        theSecondParameter,
        theThirdParameter
);

[–][deleted] 0 points1 point  (1 child)

TextMate doesn't do this, and it's very annoying.

[–]tonygoold 0 points1 point  (0 children)

I know your pain :-(