How it works...
In these four steps, we saw the use of the question mark operator and how it can avoid the boilerplate typically associated with guards. In step 3, we create a function that prints the file contents if the file has been found (and was readable), and, by using the ? operator, we can skip checking the return value and exiting the function if necessary—it's all done with a simple ? operator.
In step 4, we not only call the previously created function, but we are also printing the result to show how it works. On top of that, the same pattern is applied to the (special) main function, which now has a return value. Therefore, ? is not limited to sub-functions but can be applied throughout the application.
In just a few simple ...
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