函数和参数

Function and Arguments

Robert C Martin

是什么意思

Output arguments are harder to understand than input arguments. When we read a function, we are used to the idea of information going in to the function through arguments and out through the return value. We don’t usually expect information to be going out through the arguments. So output arguments often cause us to do a double-take.

在他的书“The Clean Code”第 3 章“函数”中,当他谈到函数中的参数时,他指的是哪个参数?

他的意思是我们不应该有修改输入参数的函数。 例如(来自"Clean Code"):

public void appendFooter(StringBuffer report)

他说 report 更像是 output argument here because this function 修改它。更好的方法是拥有 Report 对象并调用:

report.appendFooter();

或代替:

public void changeContactDetails(Person person)

person.changeContactDetails()