ruby picture

RCR 256: Rename Kernel#binding

Submitted by batkins (Sat May 22 09:05:22 UTC 2004)

Abstract

The Kernel#binding method returns a Binding object for the current context. This method should be given a better-behaving name

Problem

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.

Proposal

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

  

Analysis

Makes code clearer, makes Kernel simpler, allows programmer to use "binding" as a variable name without fear of ambiguity.

Implementation

class Binding
    def self.current
        # do whatever Kernel#binding does
    end
end
ruby picture
Comments Current voting

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.


Strongly opposed 0
Opposed 7
Neutral 0
In favor 1
Strongly advocate 1
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .