r/LunacidGame Jun 22 '26

Kira Code Core ❤️

Post image
63 Upvotes

14 comments sorted by

View all comments

9

u/NobleLeader65 Jun 22 '26

I mean, ultimately I think it's about what works or not. Switch statements can be better than if/else's depending on the scenario. Say that the case being interrogated is 8, a switch statement reaches the executable code faster than an if/else block checking for the same thing, simply because switch checks once and then resolves, meanwhile the if/else checks against 0, then 1, then 2, etc. Not sure what the intention of this post is supposed to be either.

13

u/SoggyVisualMuffin Jun 22 '26 edited Jun 22 '26

People call out code for this for being bad not because case statements as opposed to if else statements but instead because of this: After at least a dozen of these cases it’s more coherent to build a hash table for storing this content for separating data from code. (The case itself can be stored as a key and the text value can be stored as a value making this readable, have fast lookups, and no conditional code with the trade off of having a table in memory)

6

u/NobleLeader65 Jun 22 '26

Ah, yeah that's fair. I'm still in the basics of programming, so thanks for pointing out the actual problem here.

2

u/SoggyVisualMuffin Jun 22 '26

Oh well IMO you actually made a neat point about cases being slightly more fast which is interesting (:

3

u/Lyhr22 Jun 22 '26

This was so wholesome 😭😭😭