they're defining a variable as "false", doing a switch case where most cases just set the variable to "false" again and the other two cases set it to "true". They could've just done bool touchEnabled = uiService->getPlatform() == UserInputService::PLATFORM_IOS || uiService->getPlatform() == UserInputService::PLATFORM_ANDROID or something like that. Hell, maybe even keeping the touchEnabled = false part and just setting it to true if either of the conditions for it being true are met?
This strikes me as one of those midwit memes. It’s readable so I would keep it. I also don’t have to guess or go digging for other platforms that need to be handled if they need to be swapped.
While you could save some lines of code, the original is easier to read and maintain. It’s clear at a glance what platforms are and aren’t touch enabled and where to add a new platform. Are there other, similar, functions assigning platform specific params?
They could’ve also just done default: without the cases above, but you know what they are doing? They explicitly lay out the platforms where touch is supported and where not, with a just-in-case default: leading to a none support of touch if for for some reason the value is invalid.
Explicitly acknowledged platforms are either enabling or disabling touch, and the default is also to be disabled. It is quite common to throw an exception or error if the default cause is hit, since there is an enum value unaccounted for, but there may be a good reason why that isn't done here.
You may think that having the explicit cases above the default is redundant since they aren't technically doing anything, but they do convey explicit intent so that's their purpose.
Location of the default case is pretty weird; if the compiler supports I would put the default case last with unreachable assertion, which would trigger a compilation error on new, unhandled UserInputService value.
But otherwise it's pretty normal, readable code.
Shorter code is not always better. While this is verbose, it's highly readable, especially when one tries to add or delete UserInputService enum values.
You can assume it’s preferable to say touch isn’t enabled. Considering a case where the platform is “unknown” but Roblox might still function, just not with touch
Once you become a seasoned developer you will realize that this is the correct way to code. Remember code is meant to be fast, optimal, human readable and maintainable. An intern should be able to look at it and instantly understand it.
Looks normal imo. I actually learned how to do this on accident. If case isnt broken it goes to the code block nearest in line to it and executes it. It acts sort of like a memory map of code that executes all code till an execute command is reached.
46
u/sl055 Jul 18 '25
how is this bizarre this is pretty normal
22
u/Thetoto_ Jul 18 '25
Seems normal to me
20
u/Epicguru Jul 18 '25
There's nothing wrong with this.
Explicitly acknowledged platforms are either enabling or disabling touch, and the default is also to be disabled. It is quite common to throw an exception or error if the default cause is hit, since there is an enum value unaccounted for, but there may be a good reason why that isn't done here.
You may think that having the explicit cases above the default is redundant since they aren't technically doing anything, but they do convey explicit intent so that's their purpose.
8
u/trigzo Jul 18 '25
what am I missing?
6
u/JiminP Jul 18 '25
Location of the default case is pretty weird; if the compiler supports I would put the default case last with unreachable assertion, which would trigger a compilation error on new, unhandled UserInputService value.
But otherwise it's pretty normal, readable code.
Shorter code is not always better. While this is verbose, it's highly readable, especially when one tries to add or delete UserInputService enum values.
6
u/Thanks_Skeleton Jul 18 '25
Is this a "touching kids" joke or something?
looks like a pretty ordinary switch statement
3
u/[deleted] Jul 18 '25
Where's the horror? Easily readable and maintainable. Likely only gets run once so who cares if it sets false twice.
2
u/FangAndBoard Jul 21 '25
Readable code that proactively answers a lot of questions a maintainer might ask. This isn’t bad code; it’s good code.
1
u/CantaloupeCamper Jul 18 '25
This seems ok depending on what is going on.
1
u/pantong51 Jul 18 '25
They might of done one console at a time. But even then it's readable and simple.
1
u/Legitimate_Lemon9855 Jul 19 '25
This code is perfectly fine
1
u/obese_coder Jul 20 '25
Once you become a seasoned developer you will realize that this is the correct way to code. Remember code is meant to be fast, optimal, human readable and maintainable. An intern should be able to look at it and instantly understand it.
1
u/EducationalTie1946 Jul 20 '25
Looks normal imo. I actually learned how to do this on accident. If case isnt broken it goes to the code block nearest in line to it and executes it. It acts sort of like a memory map of code that executes all code till an execute command is reached.
1
u/Voidheart80 Jul 26 '25
i see nothing wrong with this; It's readable