C++ as a Mother Language ------------------------ By Yitzhak Gerber pp. 98 - 101: "the final version" ----------------------------------- List of Errors (not ordered by importance): (0) No #ifndef protection against multiple inclusion (it may be argued that it's irrelevant here). (i) Make the scaling type a `typedef', for easy modification (too early for `templates', in the book). (ii) Long functions inside class (inline), but short functions - outside (in the book, inlining discussed just before). (iii) Assignments at Ctors [should initialize data members]. (iv) "Magic Numbers" in code [should use `enum' values]. (v) Clumsy code at Ctor [redundant criticism, if avoids code dup]. (vi) Code duplication at Ctor and set_a() and set_b() [extract the common parts as independent functions]. (vii) Error response is too harsh (exit()) [use ILLEGAL values - too early for exceptions]. (viii) Error messages go to `cout' and not to `cerr'. (ix) Inspector methods are not `const' [make them `const']. (x) BAD METHOD NAMING: _a/_b [instead of length/width/height]. (xi) BAD METHOD NAMING: set_/get_ [instead of function overloading]. (xii) Horrifying coding style at rect::area(), rect::perimeter(). (xiii) rect::show() is bound to `cout' only [use `ostream' argument]. (xiv) Could have used `operator<<' (though, too early in the book). (xv) main() implicitly returns `int' (a syntax error in C++) [make it explicit]. (xvi) No initializations for `z', `s' at main() [switch declarations order, and initialize]. (xvii) Code duplication in main() [exercise all rectangles at a single function]. (xviii) main() should be on a separate file [separate from "rect1.cpp"]. (xix) File "rect1.h" is not self contained [#include <stdlib.h> and <iostream.h>]. (xx) Horrible indentation. (xxi) #include <process.h> is non-standard (xxii) All printings are of '\n', not even a single `endl'. (xxiii) Loop variables should be declared inside loops (at show()). (xxiv) Private part is better put at the bottom of the class. Copyright (c) 1999 - 2003 by Yechiel M. Kimchi. All rights reserved.