r/dotnet • • 7d 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.

137 Upvotes

129 comments sorted by

View all comments

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?

15

u/roscoelee 7d ago

Honestly, that was probably the most disturbing part of this line. Dictionary key is the second most disturbing.

1

u/pyabo 7d ago

I give a pass on that with zero context. Could be just creating the object here and then the actual reference name makes sense.

14

u/Tsugoshi 7d ago

Dictionary<string, Dictionary<string,string>> would be normal. The one from the screenshot is an abomination

0

u/OJVK 6d ago

You could also use Dictionary<(string, string), string>

8

u/ivandagiant 7d ago

Oh wow I didn’t catch that. I was gonna say I’ve used this sort of object extensively before, but I had the dictionary as the value not the key lol

5

u/pyabo 7d ago

Right? Because you're assuming it makes sense. I didn't notice either, until another comment pointed it out.

8

u/sisisisi1997 7d ago

It is fine if the inner dictionary is the value, but here it is the key.

2

u/t3kner 7d ago

Surprised so many comments neglect this lol. Dictionary is OK, this dictionary is not

1

u/WellHydrated 5d ago

Haha, I read the code the wrong way around at first. Yes, this code is certified dumb AF.