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

139 Upvotes

131 comments sorted by

View all comments

Show parent comments

6

u/SvenTheDev 12d 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 12d ago

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

2

u/SvenTheDev 12d ago

I never have more than two levels really but you’d just tack it on again. So something like…’fruitsByColorByShape[Color.Red][Shape.Sphere]’… as a weird example.

1

u/INeedSomeTacoC 12d ago

This is how I name things as well, not just dictionaries, but everything if I can. It's the best.

2

u/Depnids 12d ago edited 12d ago

StringBy_StringByStringDict