Spaghetti Code and Meatballs
When I transitioned over to the desktop software support team in March, I inherited a little web application that our users use to request software packages that can be pushed out to their desktops. This application was written entirely in-house by the guy that I replaced. It’s fairly good, no doubt, and written in C#. For months, I haven’t had to troubleshoot anything with this… until recently.
I have been trying to address a problem with it where sometimes different information regarding the requestor is being sent than the person who actually filled out the form. First by coincidence, but now I’m seeing a pattern. The incorrect information seems to be from the previous submitter’s session. It’s like the SessionState is not being cleared out when it expires. I have checked the code numerous times and I think I’m following the flow correctly, but sometimes it is hard to tell since I have to jump up and down throughout the file. An appropriate analogy would be something like a monkey on a trampoline. Jumbled code aside, the program should work fine. I’m currently looking into either changing the SessionState to another mode or just enacting the Session.Clear(); function on the start of a new session. I know it sounds really redundant but if it works, our users will be happy. I don’t have to like the silliness of the solution. [edit: Actually, I've added a Session.Abandon(); at the end of the submission process to clear out any lingering keys. - 07/03/06]
Maybe I’m a bit obsessive about it, but I’m a stickler for well-structured code. Not only does it make programming itself easier but it makes it easier for other people to understand what exactly is going on. Heck, some day it will make it easier for the original developer to know what they wrote. When you’re in the midst of thousands of characters during a debug, it’s best to have some legibility. I’m not really sure why functions were jumbled around so much in this application. It might have been the developer or it might have been Visual Studio. My style would have been to place most of the functions in an external include file while only keeping the main routine and private and localized functions within the main page. I’ve been thinking about rewriting it but that probably wouldn’t get me any extra points with the bosses. I know I’d better understand it but I think I’ll live. Although the overall layout and design of the site may need some tweaking…

