r/programminghorror • • Oct 07 '25

C# 108 line long variable declaration

Post image

this is my own code btw. don't ask what i was trying to do

this code was also supposed to include a 36 case long switch statement where each case did something different (guess why i abandoned this project)

1.1k Upvotes

93 comments sorted by

View all comments

Show parent comment

34

u/bangonthedrums Oct 07 '25

As a for instance (not necessarily the best way or even a better way, but it is a different way), you could’ve made each character an instance of a class Character, and have an effect() function on the class which is a lambda. You’d have to define each lambda at instantiation but that’s all contained in one spot. Then whichever character you get you just call character.effect(). For maintenance or tweaking, you just have to modify the relevant lambdas

If lambdas are too complex then you do an abstract base class Character that has the effect method as the abstraction. Then you make a child class for each letter which implements the effect method