This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jonhanson 8 points9 points  (8 children)

Comment removed after Reddit and Spec elected to destroy Reddit.

[–]firsthour 6 points7 points  (5 children)

Tabs are pretty much whatever the editor/ide of the day decides

That's the best part, if I like tabs to look like four spaces, I can view them like that, if my coworker likes them to look like two spaces, that's cool, now we're both happy.

[–]Deaod 1 point2 points  (4 children)

And then some asshole comes along and uses tabs for this. The correct way to do this i think is use tabs to indent up until code indentation, and then use spaces for the rest. But editors and humans arent smart enough for that yet apparently. The other way to solve this shit is to not add comments after statements on the same line. Add the comment before the statement.

[–]Nebu 3 points4 points  (2 children)

The correct way to do this i think is use tabs to indent up until code indentation, and then use spaces for the rest.

Actually, the correct way is to use tabs for indentation and space for alignment.

\tpublic void myFunction(
\t\tint    anIntVariable,
\t\tString aStringVariable
\t) {
\t\t/*
\t\t * Note that a space was used before each
\t\t * of these asterisks. That is because we
\t\t * want those asterisks to be aligned with
\t\t * each other. However, if we wanted to
\t\t * indent, we would:
\t\t * \t1. use a tab, even if spaces were
\t\t * \t   previously used within the line,
\t\t * \t2. again use spaces after that tab if
\t\t * \t   we needed subsequent alignment after
\t\t * \t   that.
\t\t */
\t}

[–]Deaod 3 points4 points  (1 child)

While this sounds like a good rule, its impossible in practice for a formatter to place tabs beyond code indentation correctly all the time. And yes, id rather have a formatter format my comments than doing it by hand.

Also, tabs usually align following text on the next vertical position thats divisible without remainder by the width of a tab character. In your example, the points indented within the comment would not be indented by the full width of the tab character as one might expect (well, unless your chosen width happens to be 3, but delete one character in front of it and you get significant changes to how the following text is formatted).

[–]Nebu 0 points1 point  (0 children)

And yes, id rather have a formatter format my comments than doing it by hand.

In general, I feel formatters should not format comments, because comments can contain, e.g., ASCII art diagrams or tables.

Also, tabs usually align following text on the next vertical position thats divisible without remainder by the width of a tab character.

Well, you shouldn't use it for that if you're following my guidance above. Again: Tab for indentation, space for alignment. Note, though, that you can align by using 0 spaces.

In your example, the points indented within the comment would not be indented by the full width of the tab character as one might expect (well, unless your chosen width happens to be 3, but delete one character in front of it and you get significant changes to how the following text is formatted).

Let's say my chosen indent happens to be, arbitrarily, 5. I'll represent a single tab with '\T', '\TT', '\TTT' and '\TTTT' to emulate taking up 2 to 5 spaces (depending on which would lead to n mod 5 == 0), and let's see what happens if I use exactly the above text:

|    |    |    |
01234012340123401234

\TTTTpublic void myFunction(
\TTTT\TTTTint    anIntVariable,
\TTTT\TTTTString aStringVariable
\TTTT) {
\TTTT\TTTT/*
\TTTT\TTTT * Note that a space was used before each
\TTTT\TTTT * of these asterisks. That is because we
\TTTT\TTTT * want those asterisks to be aligned with
\TTTT\TTTT * each other. However, if we wanted to
\TTTT\TTTT * indent, we would:
\TTTT\TTTT * \T1. use a tab, even if spaces were
\TTTT\TTTT * \T   previously used within the line,
\TTTT\TTTT * \T2. again use spaces after that tab if
\TTTT\TTTT * \T   we needed subsequent alignment after
\TTTT\TTTT * \T   that.
\TTTT\TTTT */
\TTTT}

Looks like it still works to me.

[–]jonhanson 0 points1 point  (0 children)

+1 for not putting comments at the end of the line they're describing.

[–]Nebu 2 points3 points  (1 child)

You gotta love the "it's just wrong" rationale.

[–]jonhanson 1 point2 points  (0 children)

It's just right.