2007年12月24日 星期一

[note] More Effective C++ 2/e (3)

item 25:Virtualizing constructors and non-member functions
將 constructors 及 non-member functions 的行為虛擬化。

item 26:Limiting the number of objects of a class
限制 class 能產生的物件數量。

item 27:Requiring or prohibiting heap-base objects
了解要求或禁止物件產生在 heap space 的手法。

item 28:Smart Pointers
了解 smart pointer (auto_ptr) 的用法。

item 29:Reference counting
了解 reference counter 的實作手法。

item 30:Proxy classes
了解 proxy class 的用法。

item 31:Making functions virtual with respect to more than one object
讓函式可以根據一個以上的物件型別來決定如何虛擬化。

item 32:Program in the future tense
在未來時態下開發程式:提供完整的 class、設計容易被正確運用的 class、儘量使 code 一般化。

item 33:Make non-leaf classes abstract
如果有一個俱象類別 C 繼承另一個俱象類別 B,應該想辦法提煉出抽象類別 A,使 B 和 C 都繼承自 A。

item 34:Understand how to combine C++ and C in the same program
了解在 C++ 中使用 C 函式所會引發的問題,如 Name Mangling、Statics initialize、dynamic memory allocation 和資料結構的相容性。

item 35: Familiarize yourself with the language standard
儘可能地習慣 C++ 語言。

[note] More Effective C++ 2/e (2)

item 9:Use destructors to prevent resource leaks
使用 auto_ptr 配合 destructor,避免在 exception 發生時產生 resource leak。

item 10:Prevent resource leaks in constructors
注意 constructor 裡發生 exception 時,是否會產生 resource leak 及避免之。

item 11:Prevent exceptions from leaving destructors
當 destructor 產生 exception 時,別讓它被丟出 destructor (一定要處理之)。

item 12:Understand how throwing an exception differs from passing a parameter or calling a virtual function
了解丟出 exception 與傳遞一個參數或呼叫虛擬函式的不同。

item 13:Catch exceptions by reference
用 by reference 的方式來取得 exception。

item 14:Use exception specifications judiciously
明智地使用 exception specifications。

item 15:Understand the costs of exception handling
了解 exception handling 的成本。

item 16:Remember the 80-20 rule
讓 80% 的時間都在執行 20% 的程式碼。

item 17:Consider using lazy evaluation
考慮使用 lazy evaluation (拖挺戰術)。

item 18:Amortize the cost of expected computations
分期償還期的計算成本。

item 19:Understand the origin of temporary objects
了解暫時物件的產生時機。

item 20:Facilitate the return value optimization
了解並會協助 compiler 做 return value optimization。

item 21:Overload to avoid implicit type conversions
使用 overloding 技術來取代隱型轉型

item 22:Consider using op= instead of stand-alone op
使用 op= 來完成 op 的動作,例如使用 += 來完成 +。

item 23:Consider alternative libraries
考慮使用更理想的函式庫。

item 24: Understanding the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI
了解虛擬函式、多重繼承、虛擬繼承及 RTTI 的成本。

2007年12月12日 星期三

[note] More Effective C++ 2/e (1)

item 1:Distinguish between pointers and references
了解 pointer 及 reference 的差異。

item 2:Prefer C++-style casts
使用 C++ 的轉型。

item 3:Never treat arrays polymorphically
別以多型的方式來處理陣列。

item 4:Avoid gratuitous default constructors
非必要不提供 default constructors。

item 5:Be wary of user-defined conversion functions
小心隱式轉型所帶來的危險 ( 以explicit禁止之 )。

item 6:Distinguish between prefix and postfix forms of increment and decrement operators
了解前置式累加(減)與後置式累加(減)的本質及差異。

item 7:Never overload &&, ||, or ,
不覆寫 && || 及 ,,否則會影響傳統上 compiler 對於條件式的 short-circuit 特性。

item 8:Understand the difference meanings of new and delete
了解不同意義的 new 與 delete,如 new operator、operator new 及 placement new。

[note] Effective C++ 3/e (6)

item 41:Understand implicit interfaces and compile-time polymorphism
了解隱型介面,以及編譯時期的多型 。

item 42:Understand the two meanings of typename
了解 typename 兩種不同的意義。

item 43:Know how to access names in templatized base classes

item 44:Factor parameter-independent code out of template

item 45:Use member function templates to accept all compatible types

item 46:Define non-member functions inside templates when type conversions are desired

item 47:Use traits classes for information about type

以 traits classes 來對型別做分類及辨視型別。



item 48:Be aware of template metaprogramming

了解 meta-programming,將執行時期的運算提早至編譯期,以提高效率。



item 49:Understand the behavior of the new-handler

item 50:Understand when it makes sense to replace new and delete

item 51:Adhere to convention when writing new and delete

item 52:Write placement delete if you write placement new

item 53:Pay attention to compiler warnings

item 54:Familiarize yourself with the standard library, include TR1

item 55:Familiarize yourself with Boost