Assertions for quick input validation
Aug 20, 2025
In an interview setting, the assert
statement provides a quick way to validate input without messing around with throw
/raise
syntax. I have a tendency of mix up the error handling syntax of different languages.
Instead of this verbose approach:
return /
you can do something as simple as
assert != 0,
return /
It’s a one-liner, the messages are right there, and you’re already dipping your toes into testing rather than punting validation to a later point you might never have time for.