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 




發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *