r/programminghorror • u/True_Efficiency7329 • May 04 '26
C# longest "=" condition I've ever seen
I have been working on decompiling a unity game recently, and while a decompiled DLL isn't going to be exact source code, I am still floored by how long that set of parenthesis is. i would LOVE to see the original code
133
Upvotes
56
u/Some-Poetry8420 May 04 '26
Actually I'm super curious about that too! I would assume that Linq gets optimized by the compiler and that this is probably not really what anyone purposely wrote, but it would be great to see exactly how the syntax in each version matched up
25
u/jpeggdev May 04 '26
I know you said unity but in the auto insurance industry I had to decipher a 4700 character long stored procedure from a legacy system and the first pass before I started optimizing was horrible so I’m sure there is plenty of that out there.
3
u/Squidy7 May 04 '26
Have you used LINQ before?
Setting aside the fact it looks especially inelegant since this this is decompiled code, the whole point of it is chaining together queries like this. If it was written using the fluent syntax (as opposed to the query syntax) as the majority of .NET devs would use, the long parenthetical wouldn't be there in the actual code.
8
u/Ok_Chemistry_6387 May 04 '26
I can see some inlining going I suspect that your (from item2 in AvaliableActionsWithInherited.selectMany() were two variables before this. I bet they are arguments from a function so arg1 and arg2. Likely an IEnumerable and then the selectMany( ) from the outer frame gets resolved lazily here. Reason I suspect arguments is they don't have any binding in here and the names are lost.
Then from item2 in (from item2 in …) also is likely inlining a tuple of some kind from out of the scope.
likely something akin to var something = (arg1 => (Condition: c, Usage: ConditionUsage.Input)).concact(arg2 => (Condition: c, Usage: ConditionUsage.Output);
then the final equals is probably just that last select.
1
u/[deleted] May 04 '26 edited Jul 29 '26
Mellow feather almond harbor nutmeg cobalt velvet
This post was anonymized with Redact.dev
1
u/Gazzonyx May 08 '26
First time seeing LISP, I guess.
2
u/Choice-Mango-4019 May 04 '26
doesn't look that bad? just a bit verbose from the boilerplate for linq
1
u/StrawberryEiri May 05 '26
That kinda looks like a database query in some sort of ORM.
I don't know anything about game development, but I'm pretty surprised that databases are involved (unless we're taking about an online game's data or something).
Can someone help me understand?
1
u/Tamschi_ May 10 '26
The decompiler didn't fully restore the syntactic sugar.
SelectManyis what generally happens if you have multiple top-levelfromclauses, and most likely a few of those lambdas were entirely implicit too.That said, LINQ expressions can be very long, it's mainly a way to write those that's not as messy as this, i.e. with fewer or no parentheses.
-2
u/uvero May 04 '26
Refactor steps: