Anonymous Block Forwarding in Ruby
writesoftwarewell.com
writesoftwarewell.com
This is another case: we had a way that requires a programmer to explicitly define what she is forwarding and where she is forwarding it to. And now we have a way that requires the reader of software to know the intricacies of the language in order to understand how the "magic" works.
I truly fail to see how this makes a language better.
Haskellish syntax example:
execute f = f "test response"
perform = execute
perform print def execute(f)
f.call "test response"
end
perform = TOPLEVEL_BINDING.method(:execute)
perform.call Kernel.method(:puts)... but that optimisation has already been made† (and IIRC it is too for *args and **kwargs that just get forwarded to calls), so it mostly exists for consistency with anonymous * and ** and valueless keys, as well as documentation (making it explicit that the method accepts a block right from the signature). Here's the discussion: https://bugs.ruby-lang.org/issues/11256
I don't particularly like it given the style I like to use, but I can see how people using a certain different style would as their style would be more consistent and carry better intent.
Anyway the post linked from the OP has a more detailed rundown: https://zverok.space/blog/2023-11-24-syntax-sugar4-argument-...
It's nothing more than a piece of code that is defined somewhere but pasted in in another location.
It's a mess to debug.