How to create an unmanageable project
There is this one project that I maintain at work that really punches me in the gut. It was developed by someone who is long gone who will remain anonymous. Every time I open this project in visual studio, I die a little bit inside.
First let me give you a little background on the project. It parses the wonderfully stupid 837 document standard mandated by HIPAA(X096 and X098 if you care) . So, to defend the person who wrote this, it sucks to begin with. The EDI format is comprised of loops and segments. Each loop/segment piece is separated by a delimiter which is standardized to be a tilde ('~'). Each loop/segment piece starts with an identifier and then continues on with the data. Data pieces within a loop/segment piece are separated by a delimiter which is standardized to be an asterisk ('*'). Furthermore, some of those data pieces, depending on the identifier, may have multiple elements which are delimited by a colon (':'). Congratulations, you have been briefed on the basics of an EDI document. The official documentation for the standards mentioned above are 600+ pages. Please shoot me now.
So how do you make it worse? Let me count the ways.
The code is designed to specifically parse the intended documents. Each segment has it's own class which is custom tailored to parse and produce the intended string. Great, so now we have a metric crap ton of classes dedicated to parsing segments. The class count for these segments is somewhere around 70 which are neatly organized into one file (Yipee!). Each segment object takes a string as a constructor and breaks those data fields into named buckets. It also contains a method to re-assemble those named buckets back into the appropriate string representation. Basically each object performs these same basic functions with an extra bit of logic for validation. Is all of that parsing and assembling factored into a base class? Nope! There's no code reuse here. Why make smaller code when you can copy and paste! Furthermore, the assembling method doesn't even override ToString() like a good little object. Nope, it has it's own method "WriteString()". This behemoth weighs in at around 15,000 lines of code.
With all of that said, it does its job. It's not fast and it's very picky about the format, but it has been up and running for a year and a half now with occasional persuading by yours truly. I have plans to rewrite it, but bigger projects are on my plate at the moment. I do, however, have a working prototype that uses configuration files from the Perl Module X12::Parser. The parser happened in 150ish lines of code, and it'll take at least that again to make use of the structure to do what I need to do. Brevity can be beautiful.
Comments(2)