RCR 256: Rename Kernel#binding
Submitted by batkins (Sat May 22 09:05:22 UTC 2004)
The Kernel#binding method returns a Binding object for the current context. This method should be given a better-behaving name
Calls to binding look like local variables at first. Also, it would be convenient to save the result of binding into a variable called "binding." However, that could become confusing the way things are currently set up.
Deprecate and ultimately remove Kernel#binding in favor of a method that is less ambiguous. Perhaps Binding.current would return a Bindng object for the current context.
binding = Binding.current
Makes code clearer, makes Kernel simpler, allows programmer to use "binding" as a variable name without fear of ambiguity.
# do whatever Kernel#binding does
Method calls often look like local variables; that's not a problem in and of itself. Also, once you start renaming methods to free up variable names, it's hard to know where to stop (Array#length? String#upcase? Kernel#clone?). I don't think there's anything inherently bad about the idea of Binding.current (i.e., if that's how Matz had done it, I wouldn't be arguing for it to be changed to Kernel#binding), but at best it's an even exchange and, therefore, inadvisable in my view.
-- David Black
I actually wrote a alias for binding called #here. Makes more sense to me and it's not a local variable name one would want to use (since "here" is always changing).
Onthe other hand, Binding.current does make better OOP sense to me. We should take some cues from .net if you ask me. They are very focused on good class models --I'm sure they would take this suggest approach rather then lumping it in Kernel. It also goes along better with ideas like Binding.of_caller. So I strongly advocate this for Ruby 2.0.
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .