Tuesday, July 1, 2008

Avoid Pointers and Arrays

C++ Primer 4/e in 4.2. Introducing Pointers there is a advice:『Pointers and arrays are surprisingly error-prone. Part of the problem is conceptual: Pointers are used for low-level manipulations and it is easy to make bookkeeping mistakes. Other problems arise because of the syntax, particularly the declaration syntax used with pointers.
Many useful programs can be written without needing to use arrays or pointers. Instead, modern C++ programs should use vectors and iterators to replace general arrays and strings to replace C-style array-based character strings.』
Chinese translation is said::『Pointers 和 Arrays 容易出錯的程度令人驚訝。部份問題是概念性的:pointers用來進行低階操作,因此容易犯下簿記錯誤(bookkeeping mistakes)。另一個問題出在語法,特別是pointers的宣告語法。
很多有用的程式並不需要使用arrays 或pointers就能寫成。現今的C++程式應該使用vectors 和iterators取代arrays,並使用strings取代C 風格的、以array為基礎的字元字串。』
It seems I will more and more like C++.Little using pointers is a big gospel.Little using arrays needs time to change.

achi's Blog
achi’s English Blog

No comments: