Simple Getter/Setter comments

前端 未结 14 1041
悲&欢浪女
悲&欢浪女 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

    Commenting accessors, especially if they don't do any operations anywhere, is unnecessary and a waste of fingertips.

    If someone reading your code can't understand that person.getFirstName() returns the first name of a person, you should try everything in your powers to get him fired. If it does some database magic, throws a few dice, calls the Secretary of First Names to get the first name, It's safe to assume it's a non-trivial operation, and document it well.

    If, on the other hand, your person.getFirstName() doesn't return a person's first name... well, let's not go there, shall we?

提交回复
热议问题