[ruby-core:127589] [Ruby Feature#18915] New error class: NotImplementedYetError or scope change for NotImplementedError
Issue #18915 has been updated by zverok (Victor Shepelev). @matz I am sorry for pushing the matter after you stated your preference, but... I believe this approach defies the whole idea of the current ticket. The problem we have is that people use `NotImplementedError` against its intention. But why is this bad? I believe _exactly_ because they receive `ScriptError`-class error, when they expected a _runtime_ one. So having a new error a class that is "compatible" with the previous one makes the whole idea moot. I believe that in a dynamic language, especially one that embraces duck typing, "the method you tried to call was not implemented" is a runtime-class error (exactly like "the method you tried to call was not there"). Imagine this: * We have a library with a protocol `MyLibrary.do_something(some, arguments, output_stream)`. * With an `output_stream` being documented to be duck typed, and "should implement `write`, `flush`, `rewind`". * If one of those aren't implemented, the method _might_ raise `NoMethodError` (with some of the library's method raising for _some_ of those method: some of them need `rewind`, others do not). * Now, as the library matures, we provide our users with some `BaseStream`, which implements some utility methods, and declares the three required one to raise friendly `AbstractMethodError, "You should implment #rewind in your stream in order to reread it."` or something. We made our library's user's life easier! * ...but suddenly, what was a _runtime_ error (and might've been "not that serious" depending on the context), "in one of the code paths, you used the library somewhat wrong", caughtable with a simple `rescue`, becomes a _script_ error, "you loaded a file that wasn't supposed to work at all". Wouldn't this be unfriendly to the library's authors and users? If they've already used `NotImplementedError`, they might've been used to this behavior, but I _seriously_ doubt that they consider this behavior natural, user-friendly and worth preserving for the sake of backwards compatibility. If they are just _starting_ to use the class, they'll be up for a surprise. But if they use `NotImplementedError` and want to migrate to an `AbstractMethodError`, it is a _migration_ anyway, and they'll be aware that they need to check the behavior change. And, to be honest, I seriously doubt there would be a seriously defendable case of "no, we need 'this method is abstract' to be much more severe error than 'there is no such method', otherwise we are refusing to migrate". (In an extreme case, they can just stay on `NotImplementedError`, after all.) ---------------------------------------- Feature #18915: New error class: NotImplementedYetError or scope change for NotImplementedError https://bugs.ruby-lang.org/issues/18915#change-120103 * Author: Quintasan (Michał Zając) * Status: Open ---------------------------------------- # Abstract Introduce `NotImplementedYetError` exception that should be used in case when the codepath has not been implemented by the developer for some reason (maybe they're designing an abstract class or are designing some sort of interface to reuse later on) OR extend the meaning of `NotImplementedError` to cover those usecases so we don't have to introduce another exception # Background `NotImplementedError` is supposed to be raised `if the underlying operating system or Ruby runtime does not support them` (https://ruby-doc.org/core-3.1.2/NotImplementedError.html) However it appears that many people are misusing this exception by raising this in a superclass from which they later inherit from. I do realize that Ruby promotes duck-typing (the default RuboCop style guide has a cop for this – https://github.com/rubocop/ruby-style-guide#duck-typing). However I have seen this being discussed numerous times: * https://github.com/rubocop/ruby-style-guide/issues/458 * http://chrisstump.online/2016/03/23/stop-abusing-notimplementederror/ * https://oleg0potapov.medium.com/ruby-notimplementederror-dont-use-it-dff1fd7... * https://gitlab.com/gitlab-org/gitlab/-/issues/354314 (which I'm the author of) * https://github.com/rmosolgo/graphql-ruby/issues/2067 (here the author actually confused it with Python's `NotImplementedError`) * https://stackoverflow.com/questions/13668068/how-to-signal-not-implemented-y... # Proposal Create `NotImplementedYetError` exception OR Allow raising `NotImplementedError` in cases other than OS or Ruby runtime incompatibilities # Evaluation ### Add `NotImplementedYetError` I think a new exception is a better idea than changing the usage of an existing one just because "everyone is using it". That said it would require people to refactor their code which might prevent wider adoption of the new exception. ### Change scope of `NotImplementedError` This would require the least amount of changes possible (only a documentation change) and I believe there would be no compatibility problems whatsoever. ---Files-------------------------------- not-implemented-error-docs.patch (1.57 KB) -- https://bugs.ruby-lang.org/
participants (1)
-
zverok (Victor Shepelev)