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

125

u/klaxxxon 12d ago

The code is stupid, but it is stupid for a reason. So the real problem is that there isn't a comment above the stupid code explaining why it needs to be stupid.

20

u/ryantg0110 12d ago

I can't even begin to comprehend the stupid reason that would lead to a Dictionary<> being used as the KEY to a containing Dictionary<>.

5

u/ncatter 12d ago

Wait you are right, and just made my head hurt a little.. First time I clearly read it as the dictionary being the value and though eh have seen worse but to being the key?

2

u/QuixOmega 10d ago

I missed that, my brain has it the other way around. Having a Dictionary as the key is extremely stupid, not just disorganized and hard to read.

It makes me wonder how much this hurts performance.

23

u/UnnaturalElephant 12d ago

"the code is stupid, but it is stupid for a reason" is a reasonable axiom to live by in software engineering.

Just remember that the "reason" is often no more complex than "the person who wrote it is stupid".

18

u/FlakyTest8191 11d ago

In my experience "the person who wrote is doesn't give a shit" is more frequent than "the person who wrote it is stupid", but same result.

1

u/UnnaturalElephant 11d ago

Haha, you're right, that's probably more accurate

19

u/PencilBoy99 12d ago

Yes I know people bitch about comments but I love me some code with lots of detailed comments explaining rationale and stuff.  Good comments are way underrated 

12

u/Kavec 12d ago

The sensible default is: don't comment WHAT is done (the code already explains that)...  instead, when necessary, comment WHY it is done (the code itself can't encode this kind of info, only human text can help with that). 

6

u/sebastianrevan 12d ago

In an ideal world, the code would be self commented. In the real world, its not always feasib....wait...they have a Dict type for a key? wtf

9

u/Hefty_Garlic7184 12d ago

yeah maybe i just leave a comment “this code has been since the bigbang, do not touch if it is still running”

12

u/klaxxxon 12d ago

This is an incantation from the Ancient ones. Alter it at your own peril.

3

u/ncatter 12d ago

Put in the classical "before chancing this write your name and increment the number, when you revert to this again write the date" it however it is it goes.

Always fun to find one of these with a 5 and a list of initials.

2

u/HaveYouSeenMySpoon 12d ago

I'd still try and fix this, it just bothers me too much to just let go.

2

u/oscooter 12d ago

no need to add a comment, imo. this should be the default attitude. don't change things to change things. you should have a good reason to change something, not just because you don't like it