I can't comment on Ruby, but as the author decided to throw in a "...AttributeError in Python" reference I figure I have two cents to add.
Unfortunately the author is out of their depth. Why are they checking for specific attributes or assuming objects are an instance of a particular class? This violates the spirit of Python. Indeed, from the Python glossary:
(Duck typing is a) Pythonic programming style that determines an object's
type by inspection of its method or attribute signature rather than by
explicit relationship to some type object ("If it looks like a duck and
quacks like a duck, it must be a duck.") By emphasizing interfaces rather
than specific types, well-designed code improves its flexibility by
allowing polymorphic substitution. Duck-typing avoids tests using type()
or isinstance(). Instead, it typically employs the EAFP (Easier to Ask
Forgiveness than Permission) style of programming.
The author even misinterprets the first reference they provide! How outrageous is that? The author links to a blog comment as "These errors are one of the largest sources of bugs.", but the actual link _explicitly states_:
The nowhere-near-ready-for-peer-review numbers I've seen suggest that
something like 70% of bugs in Java manifest to the programmer as
NullPointerExceptions.
These bugs _manifest_ using some language-specific exception, but clearly the actual bug is a different kettle of fish. It could be absolutely anything; poorly specified interfaces, well-specified interfaces that are called badly, some lower-level exception getting silently caught, inconsistent state. What does null, nil, None, NULL, whatever, have to do with this?
Comments
I can't comment on Ruby, but as the author decided to throw in a "...AttributeError in Python" reference I figure I have two cents to add.
Unfortunately the author is out of their depth. Why are they checking for specific attributes or assuming objects are an instance of a particular class? This violates the spirit of Python. Indeed, from the Python glossary:
The author even misinterprets the first reference they provide! How outrageous is that? The author links to a blog comment as "These errors are one of the largest sources of bugs.", but the actual link _explicitly states_: These bugs _manifest_ using some language-specific exception, but clearly the actual bug is a different kettle of fish. It could be absolutely anything; poorly specified interfaces, well-specified interfaces that are called badly, some lower-level exception getting silently caught, inconsistent state. What does null, nil, None, NULL, whatever, have to do with this?