FAQ 39.09 Does being a good C programmer help when learning OOC?

FAQ 39.09 Does being a good C programmer help when learning OO/C++?

graphics/new_icon.gif

No. A good C programmer is almost always a horrible OO/C++ programmer.

One of the early ideas behind C++ is that it could be used as a "better C" without using its OO or modern software engineering features. We don't think this is a desirable approach in most instances, and this book is written for organizations which want "good" OO software using C++, not just C++ programs that compile and execute correctly. With that perspective, this is the new reality for C programmers:

  • The use of arrays is evil. C++ now uses container classes.

  • The use of pointers is evil. References are "in." When pointers are used, reference counting is "in."

  • The beloved type casts of all sorts are bad.

  • Using code to find code is evil (that is, using type information and if and switch statements and downcasts to locate the right routine to call). In C++ we use virtual functions and dynamic binding.

  • Good old-fashioned char* delimited by '\0' is evil. In C++ we have strings from the class library.

  • Familiar functions such as memcpy() and strlen() either have nasty behavior or are obsolete.

So, what's left from C that's "good" C++? Curly braces and semicolons, and that's about it. Not only do C programmers have to throw away quite a bit of old technique, they also have to pick up a few new ideas:

  • Templates

  • Exceptions

  • Mutable

  • Inheritance and hiding rules

  • Operator overloading

  • Virtual functions, abstract base classes

  • Special characteristics of STL or the class library of your choice

  • Constructors and destructors, new[] and delete[]

  • Declare at first use, where no one can find it

  • And on and on and on.

Okay, we'll admit that we've had our tongue planted firmly in our cheek while writing this FAQ. It isn't quite that gloomy, and hundreds of thousands of C programmers have learned to program successfully in C++. But, our message is that the transition isn't automatic or easy, and C programmers better be prepared for a major intellectual challenge if they want to become good C++ programmers.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net