My attempt to tidy #CTRAN's code is making it worse, not better. In my attempts ...
The Last Psion | Alex @thelastpsion@oldbytes.space
My attempt to tidy #CTRAN's code is making it worse, not better. In my attempts to remove global variables, I'm ending up passing 4-7 arguments for each function, sometimes just to get information to a sub-function three levels down.
I've avoided it so far, but I'm close to creating a class for each file type, shoving the variables/tables (SetDependencyList(), SetExternalClassList()) in that and just calling each function/method in turn to generate each part of the file. No private methods, just a class to neaten each stage of building a file.
Another option is to redesign the current globals so that relevant data is packaged together. But I don't know how that looks yet, and I don't think I will until I've done an initial round of refactoring.
I know I don't have to make CTRAN any faster. On a modern machine it runs almost instantly. In DOSBox it's under a second - not as fast as the original, but not terrible. The aim here is to make the code more understandable, and to not do anything unnecessary or confusing (e.g. looking up a class name to look up the class again, or looking up a class to find one bit of information that could have been cached ahead of time).