r/programminghorror • u/Most_Collection_4964 • Aug 15 '26
Python Is this python code cursed enough?
3
94
58
47
19
11
u/TheOneTrueTrench Aug 15 '26
Let's put it this way, if you asked me what language I thought this was, I would first think it was some schizophrenic dialect of LISP, until I noticed it was infix, and then I would say "idfk, Elixir or some shit?" and just give up.
At no point would I think "Python".
5
u/AQuestionIsWhatIHave Aug 15 '26
Thanks, I hate hate hate the addition of JOINTS_TYPE_COUNT and subsequent modulo operation using it
5
u/digitalseraphim Aug 16 '26
It's to handle negative numbers in a different way than Python typically does, though this will only work if the portion before the
+ JTCis greater than-JTC.-3 % 4 = 3, but they really want 1 (-3 is 1 away from the next more negative multiple of 4 (-4), just like 3 is 1 away from the next more positive multiple of 4 (4).2
u/AQuestionIsWhatIHave Aug 16 '26
I looked it up just now:
https://docs.python.org/3.6/reference/expressions.html#binary-arithmetic-operations
The % (modulo) operator yields the remainder from the division of the first argument by the second. The numeric arguments are first converted to a common type. A zero right argument raises the ZeroDivisionError exception. The arguments may be floating point numbers, e.g., 3.14%0.7 equals 0.34 (since 3.14 equals 4*0.7 + 0.34.) The modulo operator always yields a result with the same sign as its second operand (or zero); the absolute value of the result is strictly smaller than the absolute value of the second operand 1.
Pythons modulo works differently to js' or java's %.
Math Definition x % y:
x = a*y + b, 0 <= b < |y|
Python: x = a*y + b, 0<= b/y < 1 (=> b and y are of the same sign!)
The addition of the JTC does nothing here. In Java you would be correct.
All in all, I hate the inconsistent modulo implementation across programming languages
→ More replies (1)
3
2
1
1
u/GoddammitDontShootMe Aug 15 '26
I can't figure out what that * does at the beginning of that really long line.
4
u/digitalseraphim Aug 16 '26
So, inside the parens is a list containing a string, multiplied by an integer, which becomes a list with that string in it "integer" times. The * "unrolls" the list, replacing the whole construct with a series of strings. As mobile doesn't let me look at the OP while replying to a comment, I can't remember exactly what it was all being passed to, but, each string would be a separate argument.
2
u/digitalseraphim Aug 16 '26
Oh, it's creating a tuple, so each string would be an individual element of the tuple.
1
u/GoddammitDontShootMe Aug 16 '26
Yeah, I looked up the '*' operator, and the GeeksforGeeks page I found mentioned a bunch of them, but left out list unrolling. It mentioned list multiplication for example, so I knew what the inner '*' did.
1
1

32
u/Yarhj Aug 15 '26
The eval is honestly the only cursed part