Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I document my private methods? [closed]

Private methods documentation can only be seen by who has access to the source code. Is it worth the effort spent on it?

like image 907
Jader Dias Avatar asked Nov 16 '09 17:11

Jader Dias


People also ask

Should private methods be documented?

For private members (where you will actually do the work), you may want to document the purpose of methods. But it is much more useful to document your algorithms -- why and how, not just a description of the code. Any future developer who has access to your private members will have access to your code as well.

Should you Javadoc private methods?

Nope, you shouldn't write javadoc for private methods. End users don't have access to private fields or methods so there really isn't a point in providing javadoc for them. Private fields and methods are only meant for the developer. If you really need to though, feel free to write comments for non-obvious logic.

Where do you put private methods?

Martin advises coders to always put member variables at the top of the class (constants first, then private members) and methods should be ordered in such a way so that they read like a story that doesn't cause the reader to need to jump around the code too much.

Can private methods be declared?

A private method has a body in an interface means that we can't be declared as a normal abstract method as usually do in an interface.


2 Answers

Personally, I feel that it is. Documentation is often the most useful to future developers maintaining your software - especially member documentation.

Even public API documentation is only of limited use to any audience other than a developer. Document for those following - they will thank you.

like image 91
Reed Copsey Avatar answered Sep 18 '22 15:09

Reed Copsey


It definitely is. In anything but trivial software, you can make it faster to comprehend the code with the proper use of comments, even for the original author a few months later.

like image 43
xpda Avatar answered Sep 20 '22 15:09

xpda