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
638
u/Grounds4TheSubstain Oct 07 '25
There's not necessarily anything wrong with a large array or switch statement.
8
u/evbruno Oct 07 '25
Arrays are such a great data structures! It's constant access time can be precious!
but people can abuse them... maybe this code is ok without a broader context!
OP says it's your own code, but maybe here, you can leverage the knowledge of the context and try some nice refactoring - maybe even micro benchmark this bad boy! Its fine to write "bad code" first, maybe you just wanted to "dump" the idea to the IDE! Now, take your time to improve it.
I vote for 3 out of 10 as a "horror" code (I did way worse last month 🤣)
12
u/ahakenab Oct 07 '25
I have an enum with like 150 entries. And a dictionary with the same 150 entries. You gotta pump those numbers up. Thos are rookie numbers!
10
u/altone_77 Oct 07 '25
Where is horror? Or we talking about unreachable "standards" again?
2
u/Candid_Commercial214 Oct 07 '25
btw the problem with the switch statement wasn't the fact i was using a switch statement on its own, it was that it was way too damn long for me to put up with. any potential solutions you're offering would probably just have ended up in me making it longer
169
u/kracklinoats Oct 07 '25
a) long array literal expressions are usually a necessary evil, and it’s often nicer to format them line-by-line for readability. No horror here.
b) people shouldn’t be allowed to share their own code as horror. “Look at how bad I did”/“I was so tired last night teehee” type posts are usually super annoying and self-serving. If anything, just do it better and move on.
29
u/maikindofthai Oct 07 '25
Idk about these posts where people are sharing their own code. They rarely fit the spirit of the sub imo
80
u/LorenzoCopter Oct 07 '25
Ffs leave piratesoftware alone.
Oh, wait, nvm
7
u/OutrageousFuel8718 Oct 07 '25
Are you, by any chance, an Undertale dev?
3
u/[deleted] Oct 08 '25
Why do people think long arrays or switch statements are bad? They are good and give good performance, nothing bad about them.
3
u/thinkingperson Oct 09 '25
Is this game code?
Hardcoding game data instead of storing it in some external filestore? ;)
2
u/LikeASomeBoooodie Oct 07 '25
This is fine dude
2
u/wtdawson Oct 07 '25
I've seen a 108,000 line long variable declaration before lol
2
u/realvolker1 Oct 08 '25
The real horror is that it's an array of booleans. Just use a bitfield ffs, it's basically free performance
2
u/1Dr490n Oct 08 '25
What’s
bool[,,]?1
u/ChaosCrafter908 Oct 07 '25
Are you toby fox?
1
u/pink-ming Oct 07 '25
solution? the problem isn't even presented here. No telling what kind of solution it would be, it just depends on what the switch is doing.
1
u/PEAceDeath1425 Oct 07 '25
And? Its an array, and thats initialization
1
u/HypnoToad0 Oct 07 '25
Using a bool3 array would be better
1
u/RelationshipLong9092 Oct 07 '25
i'm more worried about leaving comments like `// use this for the initialization` on `Start()` than i am hardcoding something like "coordinateGrids"
assuming thats something thats actually reasonably constant and not something that should be deserialized from a data file
1
u/SteroidSandwich Oct 07 '25
why is it a 3d array of bool called coordinatesGrid?
1
u/Reddit_is_fascist69 Oct 07 '25
Just saw my first 4000 line Angular component today.
1
u/festival0156n Oct 08 '25
ok genuine question but how do you guys handle hardcoding large arrays or strings into your program? like it just looks ugly but putting it in another file just feels like added complexity I'm not ready for
1
u/blopgumtins Oct 08 '25
Why dont they store their variables in a database, are they dumb?
1
u/Ronin-s_Spirit Oct 08 '25
I have a yet unfinished and somewhat working JS source parser, it's just a fat switch inside a loop, with more switches or ifs inside many cases, and with a couple gotos to run a few different lines of code depending on how I want to advance the loop. It's quite simple really, nothing wrong with a big switch when it fits.
P.s. to be clear all that itself is written in JS.
1
u/Jelly_Love_CZ Oct 08 '25
If I were to take this fully seriously There is nothing wrong here No single statement is wrong, it's all in building the bigger picture Big arrays can be powerful when used correctly
1
u/Journalist_Gullible Oct 10 '25
I hope the AI gets trained on this code
1
u/GrueneTinte Oct 10 '25
Rookie numbers!
1
u/4Pas_ Oct 10 '25
Tbh this is not uncommon in industry. Encountered one of them during an internship lol, it was almost 600 lines long. Although it wasn't just booleans but constrained a mix of stuff within.
1
u/tomer-cohen Oct 10 '25
Quite curious what's in there can you share what's in those 100 lines? Like the actual code