Simple Getter/Setter comments

前端 未结 14 1027
悲&欢浪女
悲&欢浪女 2020-12-04 07:16

What convention do you use to comment getters and setters? This is something I\'ve wondered for quite some time, for instance:

/**
 * (1a) what do you put h         


        
14条回答
  •  遥遥无期
    2020-12-04 07:48

    I'd say only worry about commenting getters and setters if they have some sort of side effect, or require some sort of precondition outside of initialization (i.e.: getting will remove an item from a data structure, or in order to set something you need to have x and y in place first). Otherwise the comments here are pretty redundant.

    Edit: In addition, if you do find a lot of side effects are involved in your getter/setter, you might want to change the getter/setter to have a different method name (ie: push and pop for a stack) [Thanks for the comments below]

提交回复
热议问题