« back

An Elegant Require Farm is still a Require Farm.

21 Aug 2012


Lisa Douglas would say that a little glitz makes everything better. With or without glitz, a farm is a farm.

While working with Doug, we were adding a class to my app. We ran the app and got an error. He said I needed to require the class at the top of the other class we were working in. I said, "Oh, I have something for that." It was this...

1     ttt_path = File.expand_path("../", File.dirname(__FILE__))
3     files = ["ui", "ai", "board", "player", "computer_player",</br> "human_player", "scoring", "game", "runner", "message"]
5     files.each do |file|
6       require "#{ttt_path}/lib/#{file}.rb"
7     end

He cringed.

He then explained that since the goal is managing dependencies, if you wanted to reuse a class and you do not have the requires in your class file, you have to then hunt down all of the dependencies. This sold me since I seem to really have a thing for reusability. He also pointed me to Micah's blogpost. One thing that I was experiencing first hand was this. "Every time you add, delete, or rename a file you have to remember to update the require farm file. It’s easy to forget. And the order of requires can get very hard to manage especially if you end up with cyclic dependencies." I only have a handful of files so I can imagine how this could get out of hand very quickly. He also said "Require Farms have a tendency to require more than you want. If there’s only a portion of the library you’d like to use, with the Require Farm you get the whole thing. The extra dependancies will consume more memory at run time and they may add undesired behavior to your system."

So I guess since we are talking about farms and glitz, the moral of the story is that you can't polish a turd.

comments powered by Disqus