You laugh, but this is literally how one of our access DBs does its lookups (relationships were never set up, and there are byte columns that lookup integer primary keys. Which, technically ya, I guess that’s valid.
Given that this is python I don’t know, but in a language like C it should be able to. Yet when I tried in godbolt it couldn’t, even at -O3 with gcc. https://godbolt.org/z/n4jsxeazh
Also tried with clang, which could optimise it to a simple +1 at -O2 and even -O1, but not at O3 somehow? Strange. https://godbolt.org/z/K4szrojo8
Probably one of the organized messes kind of situations. Like I get navigating through your own mess semi well because you're the only person working on it. But that's completely unacceptable when other people share the code with you. The compiler from my understanding also doesn't have that bad of a time handling code like this. Most of the performance drops came from unoptimized models iirc.
Though I do wonder now what it was like for that one dev that did help clean up his code before Yanderedev threw them out.
I think interactions/collisions and heart rate monitor also had a few things that cause more overhead than necessary.
But yeah the actual scripts that contained the code where not the issue, I think someone even tried replacing all the if-else with switch-case and it made basically no difference at all.
The compiler from my understanding also doesn't have that bad of a time handling code like this.
IIRC any LLVM based compiler (as an example) doesn't even see the difference in release mode. If-else and switch-case are broken down into the same compilation path. Debug mode does make a difference since it has to make step-debugging possible which is a entirely different case.
EDIT: Although I don't know how Cpython and other languages as well as other compilers/runtimes handle it. Generally it's well handled in compiled languages at least.
I have one fetish game that was built in RPG Maker, and it is, hands down, the most horrible codebase I've ever seen (even putting aside the fact that it's in Japanese which I'm not fluent in). Somehow, though, the game got finished and is one of the best in the genre. Even more surprising is that he managed to not get fed-up wrangling that terror of a codebase and is apparently working on another one.
Undertale infamously had some pretty wonky code despite its popularity and success; IIRC, it needed to be rebuilt completely from scratch for the console ports. At the end of the day, though, the user doesn't care as long as the product is good.
It's not really much more complicated than that though, the main conversion can easily be done with mod 12. You just need to replace a resulting 0 with 12 and determine am or pm beforehand by checking if the original 24h value is < or >= 12
this is incorrect in the majority of the bigger programming languages, as modulo doesn't have a single defined behaviour for negative operands. for truncation-based modulo implementations this will return 0 am instead of 12 am, which is not a valid notation in 12h format
A bunch of gamers get an idea for their own game and wanna try making it, but fail to really understand coding and just wanna get something working That leads to shitty solutions
It's named match in python. Also you can get away using dict containing function references as values if you're using such a old version it doesn't have match
How is this in any way an example of the use for a switch case? This is an example of people with no basis sitting behind a computer being allowed to code.
181
u/assidiou 13d ago
Should have casted it to a string. If str(str(level_curr)=="15")=="True"
158
u/Noname_FTW 13d ago
Funny. Can't level up past level 4.
258
u/a_normal_user1 13d ago
Yanderedev be like:
81
u/FallenVampireLord 13d ago
Is this pirate software's game?
52
u/Legal-Software 13d ago
This looks like the work of someone that spent 7 years at Blizzard.
22
u/WernerderChamp 13d ago
else: universe.explode()22
u/emptyevenwithin 13d ago
Ha, I saw a guy do something similar for the minutes and seconds on a clock app he was writing.
15
u/Jet-Pack2 12d ago
Also doesn't work for values between 3 and 9
7
u/Fight_The_Sun 13d ago
Pffft... use a switch case next time, n00b
5
u/Pretty-Surround4047 13d ago
Yandere dev downvoted this one
5
u/spastical-mackerel 11d ago
This is what you get for measuring dev productivity by LOC
3
u/Pretty-Surround4047 13d ago
When is level 19 update coming out
3
u/recluseMeteor 13d ago
Is this Toby Fox?
3
u/Thadrea 12d ago
This is why many games have a level cap. They ran out of bytes for more if blocks.
2
u/bem981 13d ago
O(1) function, very optimized!
2
u/mplaczek99 13d ago
This is yandaredev quality
2
u/rpeazy_mcneazy 10d ago
This is the next level of isOdd
2
u/Outrageous_Band9708 8d ago
did pirate software write this code
1
u/pjkm123987 13d ago
I'd use a dictionary for known value mapping.
1
u/Herr_Gamer 12d ago
Pure function without side effects. Testable, composable. I like it!
1
u/Charkid17 12d ago
Sometimes I think I write bad code then I remember stuff like this exists.
1
u/woodyus 1d ago
if (itworks) itworks;
1
u/creeper6530 13d ago
Why is it always game devs doing this shit
-1
u/Misel228 13d ago
I hate that Python doesn't have a switch statement. This is the best example for it.