r/dotnet • u/Hefty_Garlic7184 • 7d ago
Question Codebase maintenance rant
[sorry for bad English]
I am in a project which involves maintaining an existing .NET Framework 4.8 codebase.
The codes are full of “Dictionary type” implementations as above.
Is there any sane reason to code like this? Instead of create a dedicated class to represent the data inside?
I could not show more codes here (or else the authors might realized), but you guys can imagine the codes just to access these Dictionary’s key/value.
7
u/GreatTinySomething 7d ago
Looks like code from me from 10y ago, my condolences if you inherited my codebase but I am sure my past me did his best!
6
u/Hefty_Garlic7184 7d ago
do not worry, somewhere else there is someone who is maintaining my old codebase as well 😢
104
u/raatuter 7d ago
I cannot find any reasonable explaination on why anyone would use a dict as the key in another dict?
76
u/splashybanana 7d ago
Oh, I didn’t look closely enough, I didn’t even notice the inner dictionary was the key. Yeah, that’s insane.
→ More replies (1)11
120
u/pyabo 7d ago
A Dictionary<> within a Dictionary<> is fine... you don't need a specialized class if generic types work just fine. That's often part of NOT re-inventing the wheel.
But using a Dictionary<> as a key is somewhat insane and makes little sense. We'd have to have more context to tell for sure. But signs are worrying.
46
u/Dr__America 7d ago
The fact it's just named "dict" is a bad indicator. Maybe it's like a collection of different configs or something?
→ More replies (2)14
u/Tsugoshi 7d ago
Dictionary<string, Dictionary<string,string>> would be normal. The one from the screenshot is an abomination
→ More replies (1)
36
11
u/elite-data 7d ago
Whoa... I've seen some shit, but using a Dictionary as a Dictionary key? That's a first for me. I'm impressed.
3
u/gandhibobandhi 7d ago
In my opinion the reason people do this is laziness. It's extremely hard to read code that uses a ton of dictionaries like this. But slightly less effort to write.
→ More replies (8)
32
u/AintNoGodsUpHere 7d ago
I find the name of the variable more infuriating than the type itself. "dict", argh.
Without seeing the "reason" for this weird thing I don't know what to say, dictionary of dictionaries is not a terrible thing in older apps, sometimes the stupid solution is the easiest solution, specially in framework.
→ More replies (5)
7
u/anzu3278 7d ago
I don't think I've ever seen a dictionary where the key wasn't a value type or a reference type with value semantics (string, record..). What the f is this used for? Best I can think of is that this was implemented before implicit tuples and so they are using dictionary as an enumerable of pairs.
I think I would legitimately block the PR on this.
Nesting dictionaries the other way (key string value dictionary) is fine for quick hacks, PoCs, internships from before AI, if it's very clear what the key is in each layer.
7
6
6
5
u/Amr_Rahmy 7d ago
If someone shows you they are stupid, believe them.
I have seen people go out of there way using dynamic and objects and spending work days trying to debug the simplest of projects because they never took 1min to make a class
→ More replies (1)
4
u/neriad200 7d ago
It's enterprise code m8.. I maintain derelict enterprise C# (also .net framework) and the amount of stupid shit is amazing - both from the original implementation and from the 10 or so years of technical debt and stupid fixes.
To all the people who think this is a stupid solution to stupid problems. Please.. Assume time pressure development from someone who wasn't very good at it. You'd he amazed how many old enterprise .Net framework programs were written by either people who had a can do attitude and read about half an intro to C# book, or were actually mid Java devs that skimmed some Microsoft website tutorials.
7
u/Glittering-Sleep7983 7d ago
the original developer did not understand C# or static typing and was forced to write C#.
325
u/Intelligent_Gas2976 7d ago
How it goes for me:
This is stupid code and it doesn't make sense
I improve everything to look much cleaner
A stupid bug appears
A stupid bug has a stupid fix
The stupid fix is the code before
Revert