Chapter 7Handling Impure Functions
The world is full of inconsistencies, and the resulting unpredictability is why we have impure functions—functions that can return different values from the same input. If you use a function that expects a number from users, what prevents them from inputting hot dogs? If you have a sign-in form on a website, what will prevent users from submitting the wrong password? If your program fetches data from a database, what guarantees that data is always there? Every program needs to handle errors and unexpected results. It’s the programmer’s job to code a friendly user experience in this wild world of events. While creating code for every uncertain possibility can be boring, working without any strategy will generate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access