Honest functions – definition and understanding
A few days after his conversation with Julia about pure functions and side effects, Steve was eager to learn more. He called Julia to ask what he should study next.
Julia: Let’s talk about honest functions, null
, and Option
types,’ she suggested. ‘These concepts are crucial for writing clear, predictable code.
Steve: Sounds great! But what exactly are honest functions?
Julia: An honest function provides a clear, unambiguous contract between the function and its callers, resulting in code that’s more robust, less prone to bugs, and easier to reason about.
So what exactly is an honest function?
In the simplest terms, an honest function is one where its type signature fully and accurately describes its behavior. If a function claims that it will take an integer and return another integer, then that’s precisely what it will do. There are no hidden gotchas, no exceptions thrown out of...