Time after time you have to work with code that's not as safe as you would like it to be. Either that's someone elses code, or something you wrote at 3am 5 years ago, but it happens.
And in those cases it would be good to make that code a little bit safer and more typing-error prone.
At the same time, you want to avoid extensive testing, and if code is not covered with unit-tests, well, let's be honest, even if it is, you can't be sure you won't break anything when doing most refactoring things.
So, what I'm wondering is, what would be a shortlist for C/C++ code that can be automated to almost "find/replace all" that would make the code safer, without having high risk of changing the programs behavior.
Few things that came to my mind:
- Make all member functions const
- Make all arguments for internally linked functions const
- Remove all C style casts and replace them with C++ style casts on errors
- Turn most macros into inline functions or templates
- Change enums to typed enums
But most of them would need a recompile and manual verifications Do you have other candidates, and maybe even safer ones?
