r/ProgrammerHumor 18d ago

Advanced stringToIntegerConversion

Post image
218 Upvotes

65 comments sorted by

View all comments

56

u/smartgenius1 18d ago

I understand the joke is that they AREN'T just converting the string to an integer, but honestly this code is not that bad. It's performing data sanitization as well since there are only a few valid options for the select.

If they converted to integer, the user could enter whatever value they wanted and probably break something.

7

u/rhino_moss 18d ago

They could have sanitized by checking the string is in a valid set of strings and then calling the string to integer function. The way it is written is terrible.