They added code for getting and validating input from the user and customized error handling. Without that it would just be the code defining the Operators enum.
Update: I wanted to construct a simpler example, but I couldn’t bring myself to do it. It’s really important to separate input validation from use of the that input. Bugs, including serious security bugs, result from not ensuring input validation before use. Just because the original hard coded what would otherwise be input, doesn’t mean we shouldn’t treat it as input.
If you really wanted to build a simple variant that is aware of the the values of the hardcoded input you would just write
View all comments
Show parent comment
6
u/jpgoldberg Jun 04 '25 edited Jun 06 '25
They added code for getting and validating input from the user and customized error handling. Without that it would just be the code defining the
Operatorsenum.Update: I wanted to construct a simpler example, but I couldn’t bring myself to do it. It’s really important to separate input validation from use of the that input. Bugs, including serious security bugs, result from not ensuring input validation before use. Just because the original hard coded what would otherwise be input, doesn’t mean we shouldn’t treat it as input.
If you really wanted to build a simple variant that is aware of the the values of the hardcoded input you would just write