Re: Variables in for loop (style issue)
Ivan Vecerina wrote:
I have successfully used a bottom-up approach to convert legacy code
to becoming const-correct.
That does work if your program has a fairly strictly hierarchical
structure, and you're willing to start at the bottom rather than on the
particular segment you happen to be updating for other reasons.
When I work on code, I tend to overhaul one module at a time. That
module is unlikely to be at the bottom with no dependency on other modules.
Many programs don't have a top down structure, I know mine usually don't.
It seems obvious for example that refactoring
for const-correctness is easier than refactoring for encapsulation.
I haven't had any problems doing things like replacing global functions
with member functions piecemeal with just a minor edit here and there
that does not have a cascading effect, i.e.:
foo_func(f, p);
=>
f->func(p);
has no ripple effect. The way data flows around the program, though, put
in a const anywhere in, and you wind up putting it all around. After
all, if I change p from int* to const int*, I have to change the
internals of foo_func, as well as every function foo_func calls and
passes p on to, rinse, repeat.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]