News for hackers. Stuff that matters.
Re:Option and null in dynamic languages by zallarak on Monday December 08, 2014 @10:42PM (#8720888)
> If a language makes it easy to conflate nil and absence, to write code that does not reliably distinguish between success and failure, then bugs are sure to follow.

This is why after working on large apps in Ruby and Python, I strongly prefer Python. Accessing a non-existent key in a Ruby dictionary returns nil, whereas in Python a KeyError exception is thrown.

If you store nil in a Ruby dictionary, then you can't test for membership unless you use hash.fetch.

Re:Option and null in dynamic languages by Pxtl on Monday December 08, 2014 @11:42PM (#8721079)
Yup. Python is how I learned to stop worrying and love exceptions.
Re:Option and null in dynamic languages by nitrogen on Tuesday December 09, 2014 @01:58AM (#8721420)
You can also use Hash#include?.
Re:Option and null in dynamic languages by stevedt on Tuesday December 09, 2014 @02:00AM (#8721427)
prefer hash.fetch(:key) over hash[:key]. fetch raises NoKeyError if key not in hash.