www.4FipS.com]-      
[ FipS' NEWS ]-

 ABOUT FipS =
[ START HERE ]=
[ PROFILE ]-
[ GUESTBOOK ]-
[ FORUMS ]-

 COMPUTERS=
[ CODING ]-
[ FipS' CODE ]-
[ FSHUB ENG. ]-
[ OLD STUFF ]-

 ART & CG =
[ CG ART ]-
[ ARTWORKS ]-

 PHOTO =
[ * ABOUT ]-
[ SERIES ]-
[ SHOTS ]-
[ PANORAMAS ]-
[ MACROS ]-
[ TIMELAPSE ]-

C++ Collected Wisdom

C++ --->
[ C++ Tips, rev. 2006-05   /   ]
[ C++ Collected Wisdom, rev. 2006-09 ]
[ C++ Smart Pointers, rev. 2005-01 ]
OOP / Pragmatic UML --->
[ UML Introduction, rev. 2006-06 ]
[ UML Class Diagrams, rev. 2006-06 ]

Visitor Map      
= LINKS 
-[ CODING ]
-[ C++ ]
-[ GAME DEV ]
-[ GRAPHICS ]
-[ MATH ]
-[ LIBS ]
-[ PYTHON ]
-[ MOBILE ]
-[ FREE TOOLS ]

-[ CG ART ]
-[ PHOTO ]
-[ LEARN ENG ]

-[ E FRIENDS ]
-[ SELECTED ]
-[ MISC ]

= DUMPED 
-[ 2010 ] [ 07 ]
-[ 2009 ] [ 06 ]
-[ 2008 ] [ 05 ]


C++ Collected Wisdom : rev. 2006-09-25 by FipS

General

  • If you try to just 'hack' something in which gets the right result, you'll end up being burned by other changes along the way. /Charles Bloom/

  • You should think of every function you write as a 'service' which is provided to the coders (even if that coder is you). /Charles Bloom/

  • Throughout the development process you need to be able to change your algorithms quickly, and too much early optimization can lock you down in a bad technique. /Charles Bloom/

  • Leaving classes the freedom to change is very very important. It lets you change your mind about the implementation later if you need to, which is almost always the case. /Charles Bloom/

  • Modularization is key to efficient development. It allows one programmer to work on a module of the code base without breaking or involving other sections. /Charles Bloom/

  • 20% of the code takes 80% of the execution time (hence, optimize it!), while 80% of the code should just be written for clarity and ease of maintenance. /Donald Knuth/

  • Premature optimalization is the root of all evil. /Donald Knuth/ On the other hand we cannot ignore efficiency. /Jon Bentley/

Technical Details



  • A copy constructor is used to initialize an object with a different object of the same type. /Scott Meyers/

  • Probably the most important use of the copy constructor is to define what it means to pass and return objects by value. /Scott Meyers/

  • Pass-by-value means 'call the copy constructor.' /Scott Meyers/

  • An object's initialization occurs when it is given a value for the very first time. /Scott Meyers/

  • Object assignment occurs when an object that is already initialized is given a new value. /Scott Meyers/

  • The difference between initialization and assignment is that the former is performed by a constructor while the latter is performed by operator=. /Scott Meyers/

  • Static members are initialized to 0 by default. /Scott Meyers/



  • Constructors usually have to check their arguments for validity, whereas most assignment operators can take it for granted that their argument is legitimate. /Scott Meyers/

  • Copying is always based on an object's static type. /Scott Meyers/

  • When you call a virtual function, the function invoked is the one in the class closest to the dynamic type of the object invoking the function. /Scott Meyers/

  • Exception objects are always copied; when caught by value, they are copied twice. /Scott Meyers/

  • Never put a catch clause for a base class before a catch clause for a derived class. /Scott Meyers/

  • If you can write a constructor which uses only the initializer list, then you can declare it inline. /Charles Bloom/



  • Any C++ construct that can be called with the function call syntax is a function object.

  • Virtual inheritance means that the parent data is accessed by a pointer instead of being embedded directly. /Charles Bloom/

  • When a virtual function is called from a destructor, the function called is the function for the class currently being destroyed. /Scott Meayers/

  • Private inheritance is purely an implementation technique. /Scott Meayers/

  • Multiple inheritance is ok-good for pure virtual 'interface' classes. /Charles Bloom/

  • The fact that auto_ptrs hold exclusive ownership and can also be copied leads to significant design challenges. /Scott Meayers/

  • In the case of VC++, pointer-to-member-function can be 4, 8, 12, or 16 bytes in size, depending on what the compiler knows about the class when the PMF is declared.

Design

  • Hardcoded types are to generic code what magic constants are to regular code. /Andrei Alexandrescu/

  • Any design yielding a pointer-returning function should certainly consider returning a smart pointer instead. /Scott Meayers/ (Clients can more easily "upgrade" a returned auto_ptr to a tr1::shared_ptr than they can "downgrade" a tr1::shared_ptr to an auto_ptr.)

Jun, 2005 - C++ Collected Wisdom - (c) Filip STOKLAS (FipS) - [ www ][ Guest Book ]