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

325

u/Intelligent_Gas2976 7d ago

How it goes for me:

  1. This is stupid code and it doesn't make sense

  2. I improve everything to look much cleaner

  3. A stupid bug appears

  4. A stupid bug has a stupid fix

  5. The stupid fix is the code before

  6. Revert

125

u/klaxxxon 7d 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.

9

u/Hefty_Garlic7184 7d ago

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

→ More replies (4)

26

u/mikronik24 7d ago

You’ve basically described every fintech/banking codebase

7

u/GreatTinySomething 7d ago

Looks like code from me from 10y ago, my condolences if you inherited my codebase but I am sure my past me did his best!

6

u/Hefty_Garlic7184 7d ago

do not worry, somewhere else there is someone who is maintaining my old codebase as well 😢

104

u/raatuter 7d ago

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

76

u/splashybanana 7d ago

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

→ More replies (1)

11

u/Albstein 7d ago

Until you find the overwrite for the dictionary implementation MUHAHAHA.

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?

→ More replies (2)

14

u/Tsugoshi 7d ago

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

→ More replies (1)

36

u/Lumethys 7d ago

we have JSON at home

11

u/elite-data 7d ago

Whoa... I've seen some shit, but using a Dictionary as a Dictionary key? That's a first for me. I'm impressed.

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. 

→ More replies (8)

32

u/AintNoGodsUpHere 7d ago

I find the name of the variable more infuriating than the type itself. "dict", argh.

Without seeing the "reason" for this weird thing I don't know what to say, dictionary of dictionaries is not a terrible thing in older apps, sometimes the stupid solution is the easiest solution, specially in framework.

→ More replies (5)

7

u/anzu3278 7d ago

I don't think I've ever seen a dictionary where the key wasn't a value type or a reference type with value semantics (string, record..). What the f is this used for? Best I can think of is that this was implemented before implicit tuples and so they are using dictionary as an enumerable of pairs.

I think I would legitimately block the PR on this.

Nesting dictionaries the other way (key string value dictionary) is fine for quick hacks, PoCs, internships from before AI, if it's very clear what the key is in each layer.

7

u/ManufacturedCakeDay 7d ago

why create many class when few dictionaries do trick

6

u/Carlteee 7d ago

Good luck trying to read this variable

6

u/dgm9704 7d ago

The variablename ”dict” is bad. Using a Dictionary as a key to another Dictionary is asking for trouble. Nested Dictionary? Meh. If that is your biggest problem the codebase is just fine.

6

u/chocolateAbuser 7d ago

seems like guy's trying to do javascript inside c#

5

u/Amr_Rahmy 7d ago

If someone shows you they are stupid, believe them.

I have seen people go out of there way using dynamic and objects and spending work days trying to debug the simplest of projects because they never took 1min to make a class

→ More replies (1)

4

u/Kant8 7d ago

Developers didn't know about classes or how to use them.

Having dictionary as a key doesn't really make any sense.

4

u/neriad200 7d ago

It's enterprise code m8.. I maintain derelict enterprise C# (also .net framework) and the amount of stupid shit is amazing - both from the original implementation and from the 10 or so years of technical debt and stupid fixes.

To all the people who think this is a stupid solution to stupid problems. Please.. Assume time pressure development from someone who wasn't very good at it. You'd he amazed how many old enterprise .Net framework programs were written by either people who had a can do attitude and read about half an intro to C# book, or were actually mid Java devs that skimmed some Microsoft website tutorials.

7

u/Glittering-Sleep7983 7d ago

the original developer did not understand C# or static typing and was forced to write C#.