I have a project at work that was written entirely by a scientist who was learning programming while writing it. It is almost 200,000 lines of C++, and almost every variable is a global variable (over 2,000 global variables). I think he found out about local variables about half way through writing the project. The few local variable names are almost always x, xx, i, ii, j, jj, M, or some other single letter name. This program is prone to seg faulting and running valgrind reveals nearly a thousand instances of memory corruption. It is totally reliant on undefined behavior, to the point where it only produces the correct results on CentOS 7, and Ubuntu yields completely different and incorrect results (it's scientific code). It is completely indecipherable by anyone but the original author. We are in a unique position now where the company is going to bet everything on this one piece of software written by someone who has never written production software before. There is an extreme bus factor here, because after working on this codebase for months, I'm baffled by almost every line, and implementing the most basic features takes an incredibly long time. No other developer at the company wants to touch this code. This is by far the worst code I've ever seen. I never saw code this bad even from freshman CS students.
Given this situation, is this an appropriate case to "burn it down, and start from scratch"? What is a good strategy to make this a maintainable code base? This code will need frequent updates as research progresses, meaning freezing the code is not an option.
For clarification, this project is not yet being used in production. It has been entirely proof of concept until now, and will be used in production this summer.
For anyone curious of what this would look like, the functions look something like this.
void doSomething(void) {
sideEffect1();
sideEffect2();
sideEffect3();
...
sideEffect145();
}
void sideEffect1(void) {
if (globalVar1) {
return;
}
anotherSideEffect1();
if (globalVar2) {
globalVar1 = globalVar2 + 1;
}
... hundreds of lines later
}