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?
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:
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).