A while ago, I read about a political study that was done back in the 1950s. In it, researchers followed a set of people undergoing a career change and tested their political views before and after the change. People who were going from blue-collar jobs to white-collar jobs tended to become more conservative after a while. People who went from white-collar jobs to blue-collar jobs tended to become more liberal. Where you sit influences your perspective.

What does this have to do with programming? Well, let's try something out.

How do you feel about this Java code?


public class GlazeObject implements Renderable {
    private ClassStore store = new DefaultClassStore();
    private Formatter formatter = new DefaultFormatter();
    
    public void setStore(ClassStore store) {
        this.store = store;
    }
     
    public void setFormatter(Formatter formatter) {
        this.formatter = formatter;
    }
	
    public void render()
        …
    }
}

Do the setters bother you?

Okay, how do you feel about this Ruby code?


class GlazeObject
  def initialize
    @store = DefaultStore.new
    @formatter = DefaultFormatter.new
  end

  def render
    ...
  end
end


Feel any different?

The fact of the matter, is that they both offer the same level of access protection. In the Ruby class, you can open up GlazeObject at any time, even hundreds of lines after its declaration, and make its variables accessible:


class GlazeObject
  attr_accessor :store
end

def do_something   
  o = GlazeObject.new
  o.store = TerribleBadMaliciousStore.new
  ...
end

Yet, you won’t find too many Ruby developers who are freaked out by this. You will, however, find Java developers who don’t like the setters. And, odder still, you will find people who program in Java and Ruby who will insist that setters are evil and blithely ignore the fact that they always have all the access that they would have with a setter by default in Ruby.

The only explanation that I have for this is that we are biased by our languages. When we see that a level of protection is available in a language, we feel an obligation to use it. When it's not there, we don't seem to notice it. Where you sit influences your perspective.