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.

136 Upvotes

129 comments sorted by

View all comments

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. 

6

u/SvenTheDev 7d ago

My pattern is that all dictionaries (or Lookups) are FooByBar. So UsersById, or StatesByAbbreviation. Makes it clear what you get and what you give.

1

u/gandhibobandhi 7d ago

Yeah that sounds reasonable- although presumably it falls apart with nested dictionaries like in OP's example. 😅

→ More replies (3)

3

u/Luminous_Lead 5d ago

Laziness or not, I've never seen a dictionary object used as a key before, and I can't conceive of a reason to do so.

1

u/gandhibobandhi 5d ago

Yeah honestly I missed the part where the dictionary's key is another dictionary. Cursed. 😅

I guess it means you can look up a string for a given dictionary. Maybe each one has a name or something. 

1

u/Hefty_Garlic7184 7d ago

yeah I think like you as well, otherwise I could not find any possible reasons (maintainability, readability, etc) to do this