For simple getters/setters, like the one below, what's the best way to document it?
public float getPrice()
{
return price;
}
I'm pretty strict about coding standards, so my IDE warns me about any undocumented public/protected methods.
Option 1:
/**
* Get the price field.
*
* @return
*/
Option 2:
/**
* @return Price
*/
Or don't document it at all?
If "price" is anything other than the most obvious value, then your comment should describe what "Price" means and is used for, not just what it is called.
Some hypothetical examples:
For a good proportion of methods and properties, there is something you can say that tells the reader more than just the name will tell them. That will save other progammers a lot of time and reduce the risk of bugs. Even if it merely confirms their guesses/assumptions, it will still save them time.
In the case of "simple" values that are totally self-explanatory (e.g. Rectangle.Width), then don't waste your time typing - AtomineerUtils will create that level of documentation for you with a single keypress. (The advantage of AtomineerUtils in your case is that it supports Doxygen, Javadoc and Documentation XML comment formats, and VB, C#, C++/CLI, C++ and C code, so you can retain your existing format while massively reducing the time you spend on documentation commenting. GhostDoc will do a similar job, but it only supports Xml documentation for VB and C#)
I'd write the bare minimum to keep the linter quiet. If it's obvious what the getter/setter is getting/setting, I'd use some copy-paste documentation that makes it clear that nothing fancy is going on:
/**
* Simple getter.
* @return Price
*/
I personally consider too many getters and setters to be a code smell, as it's a possible sign that you're not providing operations at the correct level of abstraction (this is obviously not always true, but a rule of thumb).
Describe the minimum for another programmer to understand what the method does or returns.
I would use this:
/**
* @return the price.
*/
or
/**
* Returns the prize.
*
* @return the price.
*/
This duplicates the same text, but a it might be necessary if you agreed on certain coding standards that require a description and not only the tags.
I would not mention that it returns the price field, since that describes the internal representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With