Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

This question already has an answer here:

So I have a fairly big class (nearly 200 lines, so not gigantic). It started to be hard to find parts of the code, so I started making giant comments like the following:

//--------------Cue Related Methods-----------------

And then I'd have two lines above it and one below before I added the actual code underneath. Is this a bad practice? If it's not, why don't I see it in more code (it seems pretty useful to me). Is there a better way to do this or a more standard way?

share|improve this question

marked as duplicate by Karl Bielefeldt, gnat, MichaelT, Kilian Foth, Walter May 31 '13 at 11:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Related: – Robert Harvey May 30 '13 at 3:48

2 Answers 2

The better way to do it, if you can, is to split the related content out into a class with a single responsibility. If you have to split your class up like that chances are it's doing more than one thing and violates the S in Uncle Bob's SOLID principles.

share|improve this answer
Great comment. Looking back on old code I have written, the places where I used regions (or label comments in this case) should have been in their own class. – Despertar May 30 '13 at 7:21

A big reason why this is not necessary is due to the navigational and organizational benefits of a good editor, such a Eclipse. These editors have features such as outlines of all your methods, which you can instantly navigate to, the ability to highlight all instances of variables or methods, to jump to the declaration of variables or methods, and so on. With these features, one is rarely if ever simply scrolling through code blindly in an attempt to find areas - you can navigate there through helpful commands instead. With such features, comments such as that which you're suggesting, especially for a "mere" 200 lines, would all but certainly be superfluous.

To say that the comments are "bad" therefore has an indirect answer: "they're worse than not having them, if avoidable" due to their excessive size, and also are virtually never necessary with the right tools.

share|improve this answer

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