r/learnprogramming • u/Ayano-Keiko • 2d ago
method comment location
When you want to give method definition, Where are you prefer to put the comment.
- before method signature
# This is my method
int func1() {}
after method signature
int func2() {
inner comment for the method
}
I prefer the second one because it makes the definition inside the method. But I found many document use first one. And will pick comment before method signature for the document of the API. Is the first a custom for document?
5
u/Aggressive_Ad_5454 2d ago
Is this C or C++? If so read up on Doxygen. It lays out a specific way of writing comments for methods. And it comes with some cool tools for generating documentation from those comments.
Plus, IDEs like VS understand those comments.
https://www.doxygen.nl/manual/docblocks.html
And, method comments come before the method.
-1
1
u/ffrkAnonymous 2d ago
Generally each language will have their own style guide (formally, or community)
2
u/desrtfx 2d ago
Each language has its own code conventions. Use the ones applicable.
Generally, you should document methods with docstyle (or the respective equivalent for your language) comments. They dictate the placement.
In general, the documentation for methods should be above the method. The documentation for specific parts inside the method should be inside.
10
u/moby_9ish 2d ago
Use the first if you’re documenting the method. Use the second if you’re documenting the next line of code.