Re: is delete[] necessary?
On Jan 28, 2:55 am, Ian Collins <ian-n...@hotmail.com> wrote:
John Brawley wrote:
"Ian Collins" wrote
John Brawley wrote:
The program already exists and works perfectly (ugly code,
but working program...), so I'd be really scared to try to
rewrite it just to use a std::Vector instead of the
array[] it now uses.
A classic case where a safety net of thorough and robust
unit tests would remove your fear....
Uh... (*smile*) ...elaborate, possibly?
I have ooodles of little .cpp files, tests of all the pieces
that went into the program, and a half-dozen incremental
versions of the program, in various states of completion
(historical records, in case I really screw up and lose my
current best program .cpp file).... But I'm unfamiliar with
the phrase "unit tests".
If your tests are good enough, you can change the
implementation (for instance substituting std::vector for
arrays), perform any fixes necessary to get any broken tests
to pass again and know your application still works.
Not to be overly pessimistic, but...
-- There are some things that really can't be verified simply
by testing. The most obvious is the readability and
maintainability of the code---important issues in most
cases. But there are also a lot of threading issues which
don't lend themselves to testing, and some floating point
issues as well.
-- Knowing how to write effective tests is a software
engineering issue in itself, and is in some ways more
difficult that writing C++ or even good design (although
good design generally should lead to effective tests---in
both cases, you need to think about the corner cases, and be
sure they're handled correctly).
For something as direct as replacing a C style array with
std::vector, I don't think that the first is really much of an
issue, but given what John has said of his background, the
second very well could be.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34