6 ms·
I honestly don't get why things like giant switch statements are even considered bad or smelly. You have to put the dialog somewhere. What's the material differ
by resonious 2y ago
I honestly don't get why things like giant switch statements are even considered bad or smelly. You have to put the dialog somewhere. What's the material difference between putting it in a switch statement vs separate functions vs named text files? The dialog isn't going away. You still have tons of dialog.
Even for regular code organization. 100 small functions is ok but 100 switch cases is bad? It's the same amount of code, and switch cases aren't that "hard to read".
- YurgenJurgensen 2y ago100 small functions that only get called in one place is also bad. It implies that most of them are slight permutations of each other and can be cut with the right parameterisaton. Unless your logic genuinely has 100 qualitatively unique special cases, and in that case, you’re probably screwed, as there are no elegant solutions.
- yyhhsj0521 2y agoFor one, changing a typo shouldn't require any code to be recompiled.
- daemin 2y agoHaving all the dialog logic in a single switch statement doesn't mean that all the text is right in there. It can still be referring to IDs which are then looked up in a table for the right translation.
- YurgenJurgensen 2y agoThat would still be a step above the Undertale case, where the dialog was in the code. The big problem there is that your localisers now need your source code and (potentially expensive commercial) build system to test that their script doesn’t break anything. Or you end up in an expensive back-and-forth with a contractor compiling it for them. Just taking localisation strings out of the switch statement doesn’t fully fix this. You can swap out individual lines, but characters are still bound to say the same number of lines in the same order in every language, with player choice happening at the same point. This may work for simple conversations, but it will result in clunky localisations when languages differ in verbosity or sentence structure.
- resonious 2y agoWhy not? Because your compile times are long? Changing a translation yaml triggers a webpack build in a lot of web setups but nobody seems to complain about that.
- butlike 2y agoSwitch statements are O(n), but reading dialog config is O(1). It matters when trying to get the game loop to run at 60fps Edit: Evidently you can get O(1) from a Switch if the compiler converts it to jump statements. Just adding this for posterity, and to correct myself.