x is None
seems to be just fine.
I'm still waiting for std::optional
for C++. x is None
seems to be just fine.
I'm still waiting for std::optional
for C++."No type safety at all" means you can misuse a value of one type using an operation that is appropriate for a different type, and some nonsensical behavior silently occurs (or perhaps some nonportable behavior that you sneakily intended). This characterizes assembly languages, certain machine-oriented languages like BCPL, and some immature dynamically typed languages which omit run-time-type checks (the type information is there, but not checked, so that string_length happily tries to operate on an integer, so that a type problem occurs in the interpreter's kernel itself.)
In fact, the example in the article of the Ruby K/V store illustrates this problem. If optional values were used instead of an ambiguous nil for both cases, there would be two distinct results:
* Some(nil) -- or something of similar shape -- where there is a value for the key, and it is nil,
* nil where there is no value.
Obviously, the typesafety issue doesn't exist for dynamic languages, but the composability/API quality issues do -- from the numbered issues in the article, I'd say at least #s 2, 3, 4, and 7 apply to dynamic languages in general.
http://www.boost.org/doc/libs/1_59_0/libs/optional/doc/html/...
template<class T>
using std::optional = boost::optional<T>; not x
would be sufficient in the case of Python. not x
is not equivalent to "X is not None", since empty lists, zero, etc., are not truthy in a Boolean context.