I’ve been working on this driver file, one that is full of coding style and other issues, a goldmine for OPW application submissions. After a handful of trivial changes, such as converting C99 comments to classic C style, I figured I should show that I actually do have some coding skills. Well, with spaghetti, it’s easy to get too much on your fork.
One of the functions in the file is over 500 lines long. It’s a switch statement, with other switch statements as cases, wrapped in a while loop. My plan was to extract the outer switch cases to helper functions. The first one, a small one, went well. The second one, I actually completed it somehow. The result, though, was more spaghetti.
Since so many different paths though the code are possible, I was afraid to change or eliminate any variables. So, if I saw one being assigned a value anywhere, I passed it by reference. That ended up being basically all of them. One of the mentors joked with me that since there were “eleven parameters–are you sure you didn’t miss two more?” At least my pointers didn’t blow up.
Of course, I had already put in a lot of time over the weekend trying to extract the third outer case, which is 275 lines long. After 75, I stuffed it down in the bottom of my git stash, like a doomed sewing project, never to be seen again. I’m now doing what my mentor suggested, which is extracting the inner cases. Some of those are big sloppy messes in and of themselves. The time wasn’t wasted, though. My mentor praised me for having the guts to take it on. Plus, I am really learning my way around this file.