Re: C and C++
On Friday, 1 November 2013 13:41:14 UTC, Juha Nieminen wrote:
Bill Cunningham <email@example.com> wrote:
Ok what is it that's so much easier in C++ than C?
That's a good article, but it misses the most important point:
in C, you define a struct and a number of functions to
manipulate it, and you cross your fingers that no one accesses
any of the members except through your functions (or you only
provide a forward declaration of the struct, and add a factory
function, and require all instances to be dynamically
allocated); in C++, you make the data private, the functions
members, and if the struct itself needs dynamic memory (or any
other resources), you add a constructor and a destructor. In
fact, you probably add a constructor regardless, to ensure that
no one accidentally uses the date before it it is initialized.
This simple difference means that any time more than one
programmer is working on the code, or the code must be
maintained for more that six months, C++ is a better choice.
Even if you don't need polymorphism or templates or operator
overloading or function overloading.
This simple difference also means that from a practical point of
view, using C++ will result in shorter time to market, and less
total cost over the program lifetime. (Of course, the
additional features can in many cases reduce time to market and
total costs even more.)