10 Representing unknown values
This chapter covers
- Understanding how undefined values are used
- Representing the absence of a value with the Nothing type
- Dealing with values that exist but are unknown using the Missing type
Something important to deal with in any programming language is representing the absence of a value. For a long time, most mainstream programming languages, such as C/C++, Java, C#, Python, and Ruby, had a value called null or nil, which is what a variable would contain if it did not have any value. More accurately phrased: null or nil indicates that a variable is not bound to a concrete object.
When would this be useful? Let’s use Julia’s findfirst function as an example. It locates the first occurrence of a substring:
Get Julia as a Second Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.