Hacker News new | ask | show | jobs
by MarceColl 805 days ago
I think that NotImplementedError doesn't get rescued is a feature, not a bug. It means you are calling a class that has a missing part of the interface, and that's usually programmer error. For some cases where you can partially implement the spec, it may make sense to go this way, but for most abstract classes I think the NotImplementedError is still a good idea.
4 comments

I totally agree with this point of view
It's probably a bigger problem that afaik #respond_to? will return true for an "abstract" method. Which is a bit awkward.
that’s an accidental feature given that ruby’s own expectation, going by the description in the blog post, is that a required feature is missing on current platform. perhaps it’s badly named. because it leads to this faux ami. speaking as someone who has raised quite a lot of them myself, and i think that’s what sorbet raises as well.
Yeah, an unimplemented abstract method being called shouldn't really ever happen at runtime and should be some form of "Internal Error" and should aggressively try to blow up the program. I think this blog post just convinced me using it is correct. The concrete class that leaves it unimplemented should raise something else if they intend to let consumers catch it with a generic rescue clause (which is probably a code smell itself).