Article 4CA69 CodeSOD: An Objectionable Dictionary

CodeSOD: An Objectionable Dictionary

by
Remy Porter
from The Daily WTF on (#4CA69)

You may remember Karl from a few months back. Karl's organization is notorious for crunch, and it results in some awful sins when you're trying to cram 50 hours of work into the last five hours before launch.

Karl didn't write this particular bit, but dreads the day when he has to look at it or change what it does.

private void InitializeDictionaries(){ filePaths = new HashSet<string>(); preDecryptionFiles = new Dictionary<string, string>(); trailerInfo = new Dictionary<string, string[]>(); fileHeaders = new Dictionary<bool, Dictionary<string, string>>() { { true, new Dictionary<string, string>() }, { false, new Dictionary<string, string>() } }; separatedFiles = new Dictionary<bool, Dictionary<bool, Dictionary<string, List<string>>>> { { true, new Dictionary<bool, Dictionary<string, List<string>>> { { true, new Dictionary<string, List<string>>() }, { false, new Dictionary<string, List<string>>() } } }, { false, new Dictionary<bool, Dictionary<string, List<string>>> { { true, new Dictionary<string, List<string>>() }, { false, new Dictionary<string, List<string>>() } } } };}

The job of this code is to prep some data structures which will be used to store the contents of some files. Writing a class to handle that would be the obvious solution, but this developer instead went with the "let's nest a bunch of dictionaries inside of each other," approach. The separatedFiles nest their dictionaries three deep, and contain a list of strings, so that's four tiers of nested generics. I do not know why there are the boolean keys. I don't think I want to know.

None of this is a "code smell". This is a "code stench", and it's not gonna wash out.

proget-icon.png [Advertisement] ProGet can centralize your organization's software applications and components to provide uniform access to developers and servers. Check it out! TheDailyWtf?d=yIl2AUoC8zAxMwNhI49qy0
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