0

In OO languages, at least C#, everything has to be in a class. Sometimes, everything is in a namespace as well.

Just about literally all the code in one class is going to be automatically indented by a tab stop or two, which is seriously pretty pointless if it doesn't help with code readability.

The issue with just removing the indent on every single line is that the one/two lines that had the "class ..." and the "}" become out of place.

What seems like a clean and readable way to remove the extra indents in front of every single line without making the class declarations be weird?

This might be opinion-based but I don't know.

5
  • 6
    What problem are "extra" indents anyways?
    – Telastyn
    Nov 30, 2014 at 23:44
  • Just one question: How many people are working on the same code base?
    – JensG
    Dec 1, 2014 at 0:07
  • 6
    I wish the number of indents was the worst thing I worried about in my code.
    – Dave Nay
    Dec 1, 2014 at 0:16
  • They're theoretically not a problem, it's just more readable without a whole bunch of blank space on the left. Dec 1, 2014 at 1:13
  • 2
    This is a "usability of coding style" question because it contains a dilemma that has no true answer: "space seems wasteful but lack of space makes the appearance awkward." You can't have it both. To scientifically find the optimum makes it a usability research; to "discuss a dilemma" makes it a ... well, discussion - unless the stakeholders are involved (people who are really hurt by the wasteful practice of using space or by the awkward appearance of reducing space.)
    – rwong
    Dec 1, 2014 at 2:49

3 Answers 3

2

Try setting a tab equal to two spaces. It cuts back on whitespace by a factor of 2.5x, yet it provides more than enough visual feedback.

2
  • 2.5x? Isn't a tab normally 4 or 8 spaces? Dec 1, 2014 at 1:00
  • I've always used the rule 5 spaces to a tab since that approximates a half inch, which is the norm for an indented paragraph. Googling, both 4 and 8 also seem to be in widespread use (4 is used by Visual Studio), so I guess 2x is more appropriate. Still, that's a considerable savings.
    – mgw854
    Dec 1, 2014 at 3:11
1

You could leave a blank line between the class declaration and the class body, with the bracket at the end of the line, like so:

class ThisIsAClass {

public void thisIsAFunction {
    // Do stuff
}

}
0

Do as Defenestrator suggested, in leaving a blank line between the class declaration and the first member and also give a comment end braces:

class ThisIsAClass {

public void thisIsAFunction {
    // Do stuff
}// end thisIsAFunction

}// end class ThisIsAClass

Not the answer you're looking for? Browse other questions tagged or ask your own question.