我有一些參數在我的函數中接收並傳遞相同的值。我應該將所有參數變量命名爲相同嗎?這是不錯的風格嗎?
例子:
// assume numMonth = 12
// assume numYear = 2000
int promptMonth(); // returns numMonth
int promptYear(); // returns numYear
int daysInMonth(int numMonth, int numYear); // numMonth and numYear will always
int daysInYear(int numYear); // be sent to these.
bool isLeapYear(int numYear); // daysInYear() and daysInMonth() call
// this function and send it numYear
// (which would be 2000 in this case).
如果因爲相同的值傳遞給他們每個人的所有這些參數命名一樣嗎?
你所說的 「同值」 呢? –
我的意思是''numMonth''在'promptMonth()'中被賦值爲12,函數'daysInMonth()'中的參數變量'numMonth'也是12,因爲'promptMonth()'中的'numMonth'被傳遞給'daysInMonth() '。所以變量numMonth和_should_總是相同的值,在這種情況下是12。 –