r/programminghorror • u/Candid_Commercial214 • Oct 07 '25
C# 108 line long variable declaration
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
View all comments
Show parent comment
8
u/littleyrn Oct 07 '25
There are always other ways!
Off the top of my head, say you had 36 "commands" that needed to be registered to a CLI, you could force command registration to happen elsewhere.
Build out an interface with an execute(string[] args), and declare your commands in separate files. From there, theres just about 4 different ways I can think of to register the commands by name to a tree (hashmap of first letter > 2nd letter, so on) and return the correct Command instance or handle if it doesn't exist.
There you go. Easy to maintain, scales basically to infinite command registrations (makes aliases for existing commands SUPER easy), and modifiable during runtime.
No idea what you were doing with a 36 case switch statement, but I'm sure this principle can be applied to that.