Brevity Can Be a Virtue

C++ Primer 4/e 在算式这里还有一个忠告:‘Programmers new to C++ who have not previously programmed in a C-based language often have trouble with the terseness of some expressions. In particular, expressions such as *iter++ can be bewilderingat first. Experienced C++ programmers value being concise. They are much more likely to write

     cout << *iter++ << endl;

 

than the more verbose equivalent

     cout << *iter << endl;
     ++iter;

 

For programmers new to C++, the second form is clearer because the action of incrementing the iterator and fetching the value to print are kept separate. However, the first version is much more natural to most C++ programmers.

It is worthwhile to study examples of such code until their meanings are immediately clear. Most C++ programs use succinct expressions rather than more verbose equivalents. Therefore, C++ programmers must be comfortable with such usages. Moreover, once these expressions are familiar, you will find them less error-prone.’

中文版的是这样说:‘C++新手如果先前不用过以C为基础的语言,往往会被一些简洁算式困扰,特别是可能被像*iter++这种算式给迷惑 - 在第一次看到的时候。C++老手喜欢简洁,他们比较可能写:

cout<< *iter++ << endl;

而不写冗长的等价版本:

cout << *iter << endl;
     ++iter;

对于C++新手,第二种形式比较清楚,因为“递增iterator”和“撷取其值并列印”被分开来描述。然而第一个版本对大部分C++程式员自然许多。

研读这种程式码范例,直到它们的意义能瞬间明朗化,这种努力式值得的。大部分C++程式使用简洁算式,而非较啰唆的等价版本。因此C++程式员应该适应这种习惯。一旦熟悉这些算式,你会发现它们比较不容易出错。’

恩,我看得懂,但是确也经过一段不短习惯期。

achis’ English Blog