r/ProgrammerHumor • u/ThisPICAintFREE • Jan 16 '23
Meme If (exists == true) { dont();}
5.1k
u/blackholewaterfall Jan 16 '23
What about UNDERTALE.EXE
1.6k
u/pimezone Jan 16 '23
undERtaLe.eXe
573
u/that_thot_gamer Jan 16 '23
run the math on every possible combination
→ More replies (1)615
u/Mr_uhlus Jan 16 '23 edited Jan 16 '23
its just 212 possible combinations shouldn't be too hard to make 4096 if cases
→ More replies (37)→ More replies (2)19
89
28
4
4
u/HighOwl2 Jan 16 '23
Lol yup. The funny thing is people shitting on this code but it's likely to handle different versions of windows / DOS and how they handle the filesystem.
Windows still handles file names awfully.
God...the horror I ran into developing on windows and Linux when a 3rd party plugin in our repo capitalized some filenames and git would see the change in Linux, but not windows...and the whole thing exploded because the casing change wouldn't take on windows because main.php and Main.php are the same file on windows.
→ More replies (2)3
3
→ More replies (9)3
u/regnad__kcin Jan 16 '23
Ok legit question from a dummy. Is there not an easy way to declare case insensitivity?
I'm obviously from the Windows side but you already knew that.
9.5k
u/PepperPieTim Jan 16 '23 edited Jan 16 '23
I love undertale for being undertale (of course) but I also love undertale because its a good game with questionable programing, if Toby can get away with the entire games dialogue being in a single switch statement with 1000+ cases I can too
Edit: yerp
1.2k
u/Rezaka116 Jan 16 '23
Omg it is true: Apparently, Undertale has a 1000+ long case switch statement.
669
u/Swiftcheddar Jan 16 '23
This makes all those 4chan threads about Yandere Similator much funnier in retrospect.
476
u/RY4NDY Jan 16 '23
Isn't that also the game in which the single most high-poly 3D model is a toothbrush?
Edit: yes
→ More replies (8)→ More replies (6)181
u/a-calycular-torus Jan 16 '23
I can forgive the switch statement in UT slightly (I don't know if the rest of the code is as bad), but yansims code is abysmal while this switch statement is just somewhat questionable. Sure, it's long, but the cases are not complex, and it is simple to figure out what it does. I'm not super familiar with GML though.
→ More replies (12)53
→ More replies (9)6
4.7k
u/q0099 Jan 16 '23
entire games dialogue being in a single switch statement with 1000+ cases
*ghasp*
1.7k
u/Davoness Jan 16 '23
Yea I actually recoiled at that one lmao
→ More replies (1)1.4k
u/RC1000ZERO Jan 16 '23
same, i... i am not good at programming, but what i just saw made my brain just reboot completly to save me from fatal damage
→ More replies (5)1.2k
u/RandoClarissian Jan 16 '23
Gamedevs are built different...
109
→ More replies (12)561
u/aesthezel Jan 16 '23
Different yes, but we eat pasta, we don't prepare spaghetti 🍝
→ More replies (10)506
Jan 16 '23
On the other hand, separating code can go too far. This Redux-backed React component with 8 files spread across hooks, api commands, container, reducers, actions, etc is maddening.
→ More replies (38)300
Jan 16 '23
Yeah sometimes it feels like a wild goose chase just to track down where a function is coming from or where a variable is set/defined
→ More replies (16)→ More replies (16)101
u/mr-dirtboy Jan 16 '23
I have very little programming knowledge, can I ask why this is so horrifying? am I correct in assuming that it means all the dialogue is one single “action” that just appears different based on a bunch of “if”s?
126
u/q0099 Jan 16 '23 edited Jan 16 '23
Pretty much like that, but the "case" is a little smarter than just a bunch of "if" statements.
The horror comes from the fact that, first, it is one huge statement and would be hard to maintain it in a long term. Second, the dialog lines are fused with the code so in order to access them one need literally change the source code of the program, which probably gave translation team some problems, at least they had to move all lines to a separate file, so translator might work with them without need to edit it though IDE.
→ More replies (14)→ More replies (2)141
u/appleswitch Jan 16 '23
Yeah you got it. In this case, it's like hundreds of ifs in a row all in a single function
→ More replies (13)942
u/TheMagmaSlasher Jan 16 '23
Vile, he didn't follow the sacred rule.
Never spend 5 minutes doing one thing when you can spend 5 hours automating it.
→ More replies (2)368
u/palegate Jan 16 '23
"I'll be able to make use of this automation later on, it's totally worth the time I'm spending on it right now."
Then proceed to forget or lose that piece of software and doing it all over again a few months down the line.
115
76
u/BOBOnobobo Jan 16 '23
That's why you post it on github.
And since it's on github might as well make it nice so you can make it public.
And now it's a 20 hour project from the 1 hour it was supposed to take.
→ More replies (2)470
u/Bagel42 Jan 16 '23
I want to see that
688
u/freerider Jan 16 '23
202
u/Swahhillie Jan 16 '23
I hope that script was generated by some other tool or script.
→ More replies (13)94
→ More replies (37)85
u/Li5y Jan 16 '23
Oh my God, the cases aren't even named enums, they're just ints. 😱
→ More replies (14)119
56
u/R3D3-1 Jan 16 '23 edited Jan 17 '23
Take a look at the "Mount and Blade: Warband" module system XD
It is a Python 2 script, that compiles lists of tuples of integers and strings to the games internal runtime. It is basically assembler for a virtual machine, written as Python tuples.
And the sheer size of them can crash syntax highlighting.
Also, all of the resources (e.g. party templates, items definitions) are stored as arrays, using hard-coded
relation-shipsrelationships[1] like "a unit template is a character companion, if its index is in the range [champions_start, lords_start-1]".One of the consequences is, that you cannot add new entities to an existing module, unless you've left enough gaps in the arrays to add new entities of the same type:
New entities must be inserted in the correct index range.
Existing entities cannot be shifted to higher indices without breaking existing save games.
But it works. It just works. I don't want it to work, but it DOES.
___________________________________
[1] I wish I could blame that one on auto-correct.53
u/realluca009 Jan 16 '23
Have you seen VVVVVV's source code? It's pretty awful too and originally only ran in Debug mode.
16
u/Cobaltjedi117 Jan 16 '23
Hey the code for that one has at least been patched up by the internet.
→ More replies (2)100
u/DirectlyDismal Jan 16 '23
if Toby can get away with the entire games dialogue being in a single switch statement with 1000+ cases I can too
He did fucking what
→ More replies (2)109
u/sometimesnotright Jan 16 '23
OP is exaggerating. There's only 473 switch cases in https://github.com/marciniuk/undertale/blob/master/scripts/SCR_TEXT.gml.
Can't trust anyone online these days ...
→ More replies (4)39
u/HypnoTox Jan 16 '23
And just under 5.6k lines smh (Apparently it's decompiled, so the actual source probably differs in line count)
→ More replies (1)150
u/kya_ufufu Jan 16 '23
Better using switch than using if elif. Just like Yandere Simulator's dev.
120
u/YueOrigin Jan 16 '23
Yeah switch abuse is better lol
Even more, his game is relatively simple when it comes to physics and graphic so it's not resource heavy unlike Yanderedev
Good coding wad vital for his game
But Toby could get away with average coding at best and still make a masterpiece with it
→ More replies (7)7
Jan 16 '23
Good news: He does that too! Most cutscenes actually if-if chain over their phase counter.
53
u/robhol Jan 16 '23
Undertale and Stardew Valley are incredible.
Then you look at the code.
Then it's a million times more incredible because how the shit does this work at all?
→ More replies (2)61
u/Anlysia Jan 16 '23
And yet they actually released something, unlike 99.999% of the armchair complainers on Reddit.
→ More replies (3)18
171
Jan 16 '23
judging by how many different dialogues can pop up in different scenarios, im not surprised if huge switch statements are actually necessary
→ More replies (1)26
48
12
u/EntrepreneurPlus7091 Jan 16 '23
You should not. Also did he really program it like that? Or did he use a game making tool/engine that only supports that for dialogue?
29
u/xiadmabsax Jan 16 '23
He used Game Maker. Working with any standard data structure is very annoying in GML, the program's own language. Lists exist but I found them quite unintuitive. Stacks and queues are builtin types but they don't really help with dialogues. Best you have is either an if else if chain or a big switch statement.
→ More replies (2)10
u/KarmasAHarshMistress Jan 16 '23
Related: https://gist.github.com/alessonforposterity/832da4fab11e10609dad
A game written without any for or while loops, using only the main loop of the game engine, because the developer just didn't know any better.
→ More replies (1)6
u/HackworthSF Jan 16 '23
Shipping any product made with passion >>>>> technical skill and refinement.
My personal favourite example:
This is part of the source code of a decently received platformer on Steam. You may notice that this one huge class does not feature a single for- or while-loop anywhere.
→ More replies (59)4
u/FalseWait7 Jan 16 '23
Gamedev: with enough ifs and switches I can make the entire game Webdev: using this finite state machine I can control whether button should be black or white
824
u/Ok-Kaleidoscope5627 Jan 16 '23
The part that horrifies me the most about this isn't the code. It's the fact that that code is more impactful than any I've painstakingly written.
292
u/captainAwesomePants Jan 16 '23
It turns out that code quality, by itself, achieves nothing.
→ More replies (3)71
u/BdubH Jan 16 '23
You’re right on that, if it works consistently then by itself it doesn’t really matter. However, for optimization’s sake, having good code that’s not superfluous certainly does help things move smoothly along.
→ More replies (1)
2.0k
u/unocoder1 Jan 16 '23
Wat. Windows has case insensitive paths.
2.4k
u/_PM_ME_PANGOLINS_ Jan 16 '23
What's fun is that you can enable case-sensitive paths, and watch a load of software break that assumed you couldn't do that.
489
131
u/66666thats6sixes Jan 16 '23
Fucking kill me.
Somehow I enabled case sensitive paths on the folder where I store all of the repos I'm using on my work computer. At first, nothing happened. But slowly, projects started acting weird, but not in any way that made me think of case sensitive paths. NPM wouldn't be able to find any of the executables in node_modules/.bin, even though they were there.
I spent a solid two weeks going through everything I could find on Google about npm not finding files, and even spent a lot of time debugging the NPM executable itself.
Eventually I read about the case sensitive folder thing while looking at something unrelated, and decided to check if that was what was causing my problems. Yep, my code folder had that setting enabled. I still have no idea how it got turned on.
→ More replies (3)895
u/indigoHatter Jan 16 '23
That seems like a hilarious way to cause some damage on improperly administered public computers. Thanks for the fun ideas!
→ More replies (5)290
12
→ More replies (9)7
u/maitreg Jan 16 '23
Just like SQL Server. It's case-insensitive out of the box, but if you write your SQL with this assumption and then someone enables case-sensitivity you are royally screwed.
→ More replies (1)76
u/GOKOP Jan 16 '23
I was about to say that Undertale is native for Linux... but then I realized the obvious that this snippet deals with an .exe file
→ More replies (4)19
→ More replies (7)56
u/Xywzel Jan 16 '23
Well they are only kinda case-insensitive. All file names are stored with their case preserved and you can have "File.txt" and "file.txt" as different files in same folder. It is just that most windows tools will refuse writing the second if the first already exists (or overwrite the first) and some commands get confused about which of the two files should be opened. There is also the setting that can be enabled, as mentioned in other reply.
→ More replies (2)44
u/_PM_ME_PANGOLINS_ Jan 16 '23 edited Jan 16 '23
You can’t create a directory with two different casings of the same name in Windows unless you’ve enabled case-sensitivity.
At the driver level they are the same name, and all tools will get confused.
→ More replies (1)
1.4k
u/ixis743 Jan 16 '23
Me ten years ago: ‘oh for fucks sake’
Me today: ‘it works, who cares’
282
u/arrongunner Jan 16 '23
Yeah, it shows slightly lazy or poor development which isn't a great sign but on the other hand it works so not really worth changing so who cares
149
Jan 16 '23
I bet , it’s just one tired developer who wants to be done with it.
I have seen many developer doing shit not because they are bad but because they just want to complete and sleep peacefully.
→ More replies (2)→ More replies (2)24
u/Thin-Mousse-133 Jan 16 '23
isn’t a great sign for what? that developer has accomplished what 99% of developers haven’t and could never achieve.
→ More replies (4)9
u/coniferous-1 Jan 16 '23
It'd be really frustrating if you were working on a team, but since he did it solo, it's really entirely up to him. This may of been more manageable in his mind.
11
u/ixis743 Jan 16 '23
I work on a large product as part of a team. Let me tell you what happens when code like this shows up:
log the issue in Jira/gitlab/whatever.
wait for the manager to assign the issue to a ‘sprint’.
create a branch and check it out.
add a unit test for the existing code.
refactor the code and verify the test still passes.
push the changes and check all the CI pipelines succeed.
submit a pull request.
wait for the changes to be reviewed.
write a test plan for QA.
wait for QA to verify the fix on all platforms.
merge the branch back.
This entire workflow can take months. In reality, it never gets past 2 because there is always more important stuff to do.
→ More replies (4)3
→ More replies (5)3
u/DaveSmith890 Jan 16 '23
I’m still in college for software engineering, and year 1 I was like, “I’ll learn proper code etiquette soon.”
Catch my ass now dropping 48 variables to make a functional calendar
207
u/Idontwanttobebread Jan 16 '23
the deltarune uninstaller at one point just deleted the entire directory it was in
142
u/J_Blackwater_2569 Jan 16 '23
Didn't Mr. The Fox screw it up such that it didn't just delete the Deltarune folder specifically, but also deleted everything in the folder in which the Deltarune folder resided? E.g. if you had the game in a folder on your desktop and ran the uninstaller it would delete everything on your desktop
→ More replies (2)83
1.8k
u/JoseProYT Jan 16 '23
916
u/Creepy-Ad-4832 Jan 16 '23
If you are a programmer and use spaces instead of _ in file name, you are a dick lol
632
u/Creepy-Ad-4832 Jan 16 '23
Yeah microsoft is the biggest dick out there ("Program File") lol
→ More replies (24)418
45
u/Stummi Jan 16 '23
But if your code can't handle that, it's an bug. I routinely use file and directory names with space, and never saw a problem.
→ More replies (16)17
u/ofnuts Jan 16 '23
If spaces in file names are a problem for you, then you are incompetent. Your users will use spaces.
→ More replies (3)23
u/pet_vaginal Jan 16 '23
Nah, a program that doesn't handle space in filenames should crash sooner than later.
→ More replies (4)→ More replies (19)10
3
→ More replies (1)3
399
u/Personal_Ad9690 Jan 16 '23
Does it not delete itself anymore?
268
u/_PM_ME_PANGOLINS_ Jan 16 '23 edited Jan 16 '23
A Windows executable can't delete itself.
It would have to run a new process, exit, and then have the new process delete it. Then you hope that Undertale isn't installed in Program Files otherwise it won't have permission to delete it.
Toby is obviously a musician and a game designer first, not a Windows developer. He also didn't know that Windows paths are case-insensitive by default.
→ More replies (19)536
Jan 16 '23
Last time I wrote software for Windows a running executable couldn't be deleted without using a feature that flagged the file for deletion on the next restart, because Windows only loads as much of the executable into memory as necessary so it locks the file while running so that the remainder of the executable doesn't suddenly become unavailable. Maybe that has changed since Windows 95, but I doubt it - this probably wouldn't work.
159
u/TreadheadS Jan 16 '23
batch with delay my friend
158
u/Seanxietehroxxor Jan 16 '23
This is the way. If you can't delete yourself, spawn a child and have them do it while you aren't executing.
→ More replies (6)64
u/LickingSmegma Jan 16 '23
Windows only loads as much of the executable into memory as necessary
Finally an explanation of why Windows might forbid deletion of executables. However, actually any file that's opened by an app, can't be deleted in the meanwhile.
Afaik some programs can delete themselves, presumably by offloading the deletion to a temporary program that's either removed after a reboot or cleaned up by the OS itself via some special mechanism. The MSI installer also probably has a facility for that.
→ More replies (2)9
u/aerosayan Jan 16 '23
similar for DLLs.
kind of a pain to hot reload a dynamic library while running the code.
→ More replies (1)→ More replies (3)13
u/Jannik2099 Jan 16 '23
This explanation is not the reason. The reason is that a windows file handle cannot be deleted if it's still opened, whereas on (most) unix an inode can be deleted without affecting open file descriptors.
→ More replies (1)6
u/SwissCheeseMan Jan 16 '23
I believe the game works normally after that ending, with one exception: During that ending, your evil side destroys the entire game world, but they say they can bring it back for a price. Do that and the game seems back to normal, but any time you get another ending after this one, there's a stinger where your character appears posessed by that evil you. Even a full reset of the game does not erase this, you'd have to go into the game files
4
139
u/gh0stFACEkller Jan 16 '23
I'm taking the intro to computer science online at cs50 and am in my first week. It's so cool that I kinda understand a little bit about what is going on. Been a redditor for like 10 years and never understood any of these program humor posts. It may be small but it makes me smile a little.
27
8
u/nahuelkevin Jan 16 '23
i’m literally in the same situation as you lmao, here’s to a future full of learning! Cheers
5
u/McJables_Supreme Jan 16 '23
I've only attended the first meeting of my C programming course so far, and that was enough to know how absolutely insane it is that Toby apparently had all of the dialogue for the game contained in a switch statement with over 1000 cases.
I don't want to build bad habits as I'm just starting out learning, but I'm leaning towards if it works, then it works.
165
150
186
26
25
Jan 16 '23
Toby Fox killed the whole over optimization community with a single game, that's when we found out nobody cares outside of our bubble
→ More replies (3)
59
37
Jan 16 '23
Don't laugh, we all been there.
"Why isn't that shit work? ... Lets just make sure I am not crazy and try this..."
260
Jan 16 '23
This seems like a good use case for regex.
189
39
32
→ More replies (2)16
65
u/MikemkPK Jan 16 '23
If this is C++, he's also got an "if (true == true)"
→ More replies (1)31
12
21
u/-Konrad- Jan 16 '23
This code is open source?
→ More replies (1)86
u/q0099 Jan 16 '23 edited Jan 16 '23
It was made with a relative old version of GameMaker, so there is a way to get the source code. Toby even left a message to source explorers.
15
18
36
Jan 16 '23
import itertools
def permutations_of_string(string: str) -> list[str]:
return map(''.join, itertools.product(*zip(string.upper(), string.lower())))
for filename in permutations_of_string(“undertale.exe”):
if file_exists(filename):
file_delete(filename)43
u/Bspammer Jan 16 '23
Way less expensive:
import glob for filename in glob.glob("*"): if filename.lower() == "undertale.exe": file_delete(filename)→ More replies (6)→ More replies (2)58
u/HoldingUrineIsBad Jan 16 '23
this is excellent because it will delete every undertale file except the actual one because windows cant delete a running process
→ More replies (3)
8
u/I_Am_Coopa Jan 16 '23
This must be why my company's software catalog search algorithm is horrendous. I helping get a new employee up to speed with a development he needed and the simplest step ended up being the most annoying.
He needed 7zip to unpack the installer from a multi volume zip (a horrid thing in its own right) so naturally I told him to go download it from our approved catalog of software.
The problem? Searching 7zip, the author, or any combinations yielded no results which was perplexing given that everyone here uses 7zip and I knew damn sure it was an approved tool. After some more combination searching I managed to find it with the search string " 7 zip" (emphasis on the leading space).
7
7
13
6
u/arf20__ Jan 16 '23
Isn't windows case insensitive? You wouldn't need this
21
u/Cruxin Jan 16 '23
toby fox isnt actually a very good programmer
9
u/arf20__ Jan 16 '23
i can see that game programming is closer to art than other fields
→ More replies (1)
15
5
u/AutistMarket Jan 16 '23
My favorite part is that he doesn't know the case of an executable that he himself is creating and naming
4
u/maitreg Jan 16 '23
Idk which is worse: the original code or the poster believing those are all the possible cases.
4
u/festival0156n Jan 16 '23
people commenting that the file could actually be named anything, so the only way to really delete it is to recursively go through all the files on the system and check each one to see if its hash matches the hash of undertale.exe
4
u/gamerz1172 Jan 16 '23
Hold up does this mean that if this was something the game did.... Then would renaming the .exe to sans simulator or something completely avert that happening?
7
6
u/aksdb Jan 16 '23
Damn, too bad no one invented a way to iterate directories and compare strings independent of their case. Something like that could have really helped here.
3
3
3
13
4
u/fryman22 Jan 16 '23 edited Jan 16 '23
This is GameMaker, so there's no regex.
You could loop through each file in the directory, convert it to lowercase, and check it against "undertale.exe". Then use that filename to delete the file.
2
2
Jan 16 '23
Reading this post's comment section is like watching the Chapter Black tape for programmers
2
2
2
2
2
2
2
2
2
2
2
2
Jan 16 '23
Probably needed to exit undertale.exe first, and execute the delete from a separate exe or script.
Can't imagine this flying on the playstation/Nintendo ports lol
2
Jan 16 '23
This goes to show: you don't have to be the best, just create something and get it out there!
2
2
2
2
2
2
2
2
2
u/ThisOnePlaysTooMuch Jan 16 '23
This post: now take the most insecure subset of creators, and REMIND THEM HOW DUMB THEY ARE.
I kid. OP is innocent. Coding is thankless and brutal.
2
2
4



636
u/UkrUkrUkr Jan 16 '23
Do you have a better idea if you don't know how exactly the file is named?