DEV Community

Discussion on: What is the worst code you have ever seen/written?

Collapse
 
idanarye profile image
Idan Arye

It was a manual SOAP implementation for a web service. It had about 5 or 6 levels of nested function calls, each caller wrapping the XML returned by the callee within some other XML tags - the outer functions with SOAP stuff, the inner ones with the structure of the web service's response.

The wrapping was done like so:

  • Dump the XML to a string.
  • Concat the opening tag (as string) before the inner XML's string and the closing tag after it.
  • Parse the resulting string back to XML.

I saw it when we were investigating OOM crashes ("how could it be? C# has a GC!") in a production(!!!) server that was serving large requests (hundreds of MB each) and the profiler suggested there were too many huge String objects. That server was running the previous version of the web service, which was only doing that wrapping trick once - so we considered trying moving it to the newer version but then I saw that abomination...