it for? • A Lonely Operator: &. in Ruby 2.3 (and how other languages handle their versions of nil) • A Voyage to the Void Star: A history of nothingness • Summary and takeaways • Questions!
rb_cObject); rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0); rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0); rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0); // More of these, we’ll see them again soon!
"safe" and why is nil unsafe? • Should we protect ourselves from nil, or stop nil in the first place? Do we need nil at all? • If we don't handle nil, it infects everything
small " ++ (show (foxMood "Fox small")) putStrLn $ "Fox tall " ++ (show (foxMood "Fox tall")) putStrLn $ "Fox medium " ++ (show (foxMood "Fox medium")) -- Fox small Just "satisfied" -- Fox tall Just "still hungry" -- Fox medium Nothing
cached result for the search. • Just Nothing: we’ve done the search, but not found a record for the person. • Just (Just Nothing): we’ve done the search, and the result was: the database doesn't know person’s age! (Age is NULL) • Just (Just (Just 42)): we’ve found who we’re looking for and they’re 42 years old. • More @ http://bit.ly/2c5YSXQ (Luke Plant) and http://bit.ly/ 1gXXCEp (James Coglan)
of the null reference in 1965... My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement.” — C.A.R. Hoare, 2009
for ALGOL W • ALGOL influenced C (-> MRI) & Java (-> JRuby) • Most, if not all, ALGOL-influenced languages have null pointers (e.g. C, C++, Java, JavaScript, Rust)
We probably need nil, but we might not need null pointers! • Don't be a lonely operator! Ruby is a community—we're here to learn from each other • You can and should use the lonely operator (&.), but as with all tools, use it with care