Article 6GHSK CodeSOD: Limited Space

CodeSOD: Limited Space

by
Remy Porter
from The Daily WTF on (#6GHSK)

While XML is a complicated specification, and incredibly bureaucratic and verbose, it's also powerful enough that many languages, from Java to Python, have XML helper classes in their standard library.

C# is one of those languages. But just because there's a built-in library (and a wealth of 3rd party libraries with richer features) doesn't stop people from reinventing the wheel.

Ryan sends us this short C# snippet, writing: "This is the start of a method that constructs an XML file using strings."

string space4 = " ";string space8 = " ";string space12 = " ";string space16 = " ";string space20 = " ";

"constructs an XML file using strings" is clearly the WTF, but this doesn't just construct the file, it also pretty-prints the file, indenting it using one of these constants- wait, no, not constants- one of these variables.

The only saving grace I can imagine is that perhaps this code complains when you nest your document too deeply. Need more than five levels of nesting? Too bad. More likely, their current document only needs 5 levels of nesting, and when they modify the schema, and it needs more, some poor developer is going to have to add space24 and poke around inside of some ugly, convoluted, string-munging logic to make the code work again.

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments