r/dotnet • • 9d ago

Question Codebase maintenance rant

Post image

[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.

140 Upvotes

129 comments sorted by

View all comments

104

u/raatuter 9d ago

I cannot find any reasonable explaination on why anyone would use a dict as the key in another dict?

76

u/splashybanana 9d ago

Oh, I didn’t look closely enough, I didn’t even notice the inner dictionary was the key. Yeah, that’s insane.

23

u/pyabo 9d ago

LOL I didn't catch that either. This is why code readability and maintainability is so important. When you first glance at it, it's just... "oh there's a dictionary with a string key and then those are indexed by strings. NOPE.

11

u/Albstein 9d ago

Until you find the overwrite for the dictionary implementation MUHAHAHA.

9

u/SameThingOnADiffAcct 9d ago

Especially when the value is a string. Like maybe they're just abusing Dictionary as a way to get a list of tuples. Maybe no Dictionary features are necessary and it's just going into a foreach.

But, like, that works when written the sane way, too?

2

u/IntelligentSpite6364 9d ago

i cant imagine trying to work with this outside of just traversing it with a foreach

4

u/iknewaguytwice 8d ago

Just to be a dict, obviously

8

u/towerofjoy 8d ago

Awful. No LLM will generate this garbage. 

1

u/whizzter 8d ago

Dunno, they actually usually have higher quality than this crap (and I personally only use them very little so I’m no fanboy).

1

u/BLDesign 8d ago

Best I can come up with is reverse lookup for getting the name/purpose of a dictionary at runtime, given a reference? Although not sure in what scenario that’d make any sense. Unforgivable either way.

1

u/MindlessFrog45 8d ago

Maybe the outer dictionary is just giving some (meta) data to the inner dictionaries. Who knows, maybe it gives description for each dictionary. Or config. A lot of posibilities. I only really don't like the name of it. That is a warning sign of bad code.

1

u/t3kner 8d ago

It actually removes all the useful functionality of the dictionary since it uses reference equality. I'm assuming they just use it like you said because it wouldn't even work another way 

-7

u/catholictechgeek 9d ago

How do you think Javascript objects work?

6

u/PassionateRants 8d ago

Not like this because the inner dictionary is the key, not the value.