From: tenderlove@... Date: 2020-07-01T17:04:08+00:00 Subject: [ruby-core:99014] [Ruby master Feature#17004] Provide a way for methods to omit their return value Issue #17004 has been updated by tenderlovemaking (Aaron Patterson). The more I think about this, the more it concerns me. If there is some library code like this: ``` ruby def do_something_and_return_report something = do_something if RubyVM.return_value_used? create_report(something) else nil end end ``` And I am a user of the library. I want to debug my code, so maybe I do this: `puts do_something_and_return_report` If I remove the `puts`, then the behavior of `do_something_and_return_report` would be totally different. Even worse, I cannot use `do_something_and_return_report` in IRB because the behavior of `do_something_and_return_report` in IRB would be totally different than the behavior in a script. It would be very confusing to explain "the behavior of `do_something_and_return_report` is different because IRB used the return value, but your script did not". This seems like a cool trick, and something that we should use internally to MRI. But I don't think it should be exposed to users. It seems like a situation where the VM and JIT should work harder to optimize code, not library authors or library consumers. ---------------------------------------- Feature #17004: Provide a way for methods to omit their return value https://bugs.ruby-lang.org/issues/17004#change-86389 * Author: shyouhei (Shyouhei Urabe) * Status: Open * Priority: Normal ---------------------------------------- In ruby, it often is the case for a method's return value to not be used by its caller. Even when a method returns something meaningful, its caller is free to ignore it. Why not provide a way for a method to know if its return value is needed or not? That adds a room for methods to be optimized, by for instance skipping creation of complex return values. The following pull request implements `RubyVM.return_value_is_used?` method, which does that: https://github.com/ruby/ruby/pull/3271 -- https://bugs.ruby-lang.org/ Unsubscribe: