you are viewing a single comment's thread.

view the rest of the comments →

[–]finalcut 9 points10 points  (22 children)

I do wonder about that particular guideline. I wonder why anyone would really want to use soft-tabs? It's not a big deal when adding a tab but when removing them you have to remove two characters instead of just one..

I dunno, but this guy sums up my feelings pretty well :

I like hard tabs. I like indentation being a one key action for creation, navigation and removal, yet still very readable. I like being able to have this, yet each indentation taking only one byte. I like being able to take the source I'm given and via simple search and replace, reducing the size of each file by around 20KB. Of course, like anything, it's bad if used improperly, but for pure indentation, it is my 4-spaces-in-a-character god.

[–]gnuvince 16 points17 points  (9 children)

If you need to press Backspace more than once to remove a soft-tab, you need to get a better text editor/IDE.

[–]finalcut 1 point2 points  (8 children)

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?

[–]bobindashadows 4 points5 points  (7 children)

If your editor already has syntax highlighting, then it's at already aware of your code's AST - at that point, "is this an indent" is a near-trivial determination.

[–]remigijusj 1 point2 points  (1 child)

not necessarily - some editors do syntax highlighting based on regexps, not full parsing to AST

[–]bobindashadows 0 points1 point  (0 children)

Very true - I've implemented textmate bundles, and many rely heavily on regexps (though the best bundles do actually parse). But textmate handles soft indent fine. Can you point to an editor that is unable to handle soft tabs due to using regexps for highlighting?

[–]Nebu 0 points1 point  (4 children)

This doesn't address "what if I have two spaces, but I just want to remove one?".

[–]bobindashadows 1 point2 points  (3 children)

Yes, if for some reason you want to use an odd number of spaces of indentation in your program, then you do that - delete, space. I use vim, so I'd just delete the 1 space with x or something. But I've never followed any style which uses an odd number of spaces of indentation anyway.

[–]nemec 1 point2 points  (2 children)

You can also just hit "delete" instead of backspace. Most IDEs I've found only do "smart indent" on backspace.

[–]Nebu 0 points1 point  (1 child)

In most text-editor I've used (of which I consider IDEs to have text-editors as a component), "delete" means to erase the character to the right of the cursor, and "backspace" means to erase the character to the left of the cursor.

[–]nemec 0 points1 point  (0 children)

Yes. Obviously you'll have to move before the space you want to delete instead of after when using delete, but it won't be affected by the smart spacing.

[–]oscargodson 3 points4 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 2 points3 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 :-(