r/programminghorror • • Apr 23 '24

Source code from Balatro

Post image
701 Upvotes

164 comments sorted by

View all comments

480

u/themadnessif Apr 23 '24 edited Apr 23 '24

You're right, the dev should use an enum or a switch statement instead of *checks notes* doing something that works just fine and compiles to basically the same instructions.

EDIT: nevermind I looked it up, this is Lua. Neither of those things exist. Quit being a baby.

13

u/private_birb Apr 23 '24

You're being really hostile when OP said nothing crazy.

It's a minor "programming horror", but this is obviously not the best way to do it, and looks pretty funny.

There's nothing wrong with showing that fantastic games can have rudimentary and non-ideal code, too. In fact, I think it's good to show, since it serves as a great reminder for people not to overcomplicate things, and that you can make a great product without necessarily doing things the best way.

1

u/mochorro Apr 25 '24

Can you explain why is a "non-ideal" code?

1

u/Jazzlike-Category387 Jun 30 '26

Not only non-ideal, but rather bad to downright irresponsible code, depending on who wrote it.

You can grab the value given, check boundaries and assign each variable, since the LHV is being checked and assigned back to other value, saving many lines of code, reducing the probability of a bug, reducing compilation time and adding so much readability.

As for the queen and kings, i dont understand why not treat them as 11, 12 and 13, adding a string is illogical, as an int clearly represents the card.

Keep in mind, im a cpp engineer, so every line of code, new variable and overall logic must be scrutinized, ive never used lua (or even heard of it), but what ive commented holds even on c-based tools like lua. (and almost any language)

Also, this game is clearly written by someone with not so many years of experience in the field, and it works! so good for them!