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;


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;




achis’ English Blog