Using many dictionaries within dictionaries in my code

I'd say yes, create a class specifically for it. Then you can add/not-implement methods as per your usage, rather than working around any limitations you find with Dictionary with your usage.

It sounds like you'd want a tree-like structure.


Do you run into such limitations? Is your program hard to alter/debug? If so, refactor. Otherwise, profit: you're a pragmatic programmer,.

That said, I can see room for immediate improvement:

IDictionary<Guid, List<string>> x;

IDictionary<Guid, IDictionary<Guid, List<string>> y = new Dictionary<Guid, IDictionary<Guid, List<string>>();

At the least, wrap your "smelly" data structure in a class, so that you can encapsulate its implementation by providing a clean API to query/modify the data without any of the client code kowing anything about the storage details.

Then you will be free to change the implementation of the data structure at any time in the future. If you don't do this now, you may regret it later when you have 10 or 100 times as much client code, and it is too expensive/painful to refactor.

You may find that as long as you keep it encapsulated tidily, and it works, the fact that you feel it is smelly isn't really relevant - as long as code does what it needs to do and is maintainable, there is no point investing much more time into it. (I'm not advocating keeping dirty code, but we have to balance the commercial realities against our desire to achieve theoretical perfection - if code works and isn't causing any problems, then it may not always be a good use of your time to improve or refactor it. Instead, you may find that simply neutralising the risks by encapsulating it in a class and isolating the dirty implementation from its clients is sufficient for now)

Tags:

C#

Dictionary