One of the main talking points for Rails evangelism states that it is really DRY. You don't have to repeat yourself. This might be true in comparison to other languages, but when you really get down to it, it isn't very DRY at all. Take a look at your own workflow for common tasks with Rails development, and while line-by-line the code may be DRY, from a conceptual level it isn't at all.
Common task: Adding a column
I need to add in a column for Parts that will hold the Reference number. It is a required column. Here's what my workflow for this kind of task:
script/generate migration parts_add_reference- Open up the migration, add in:
add_column :parts, :reference, :string, :limit => 40, :null => false - Figure out some way (possibly in the migration) of dealing with old records that don't have this new required record. Figure out a way to handle this gracefully both with development/testing fixtures and production.
- Add in a test to verify that the validation is there
assert_validation(Part, :presence, :reference, {:good => ["XX-1234"]})
(This uses a test helper package that I may or may not release in the future. Implementation is not important. The important part is that it asserts that the validates_presence_of validation is there.) - Run the test. Test fails.
- Add in:
validates_presence_of :reference - Run the test. Test passes.
- Add in the functional test to make the field is displayed in the new/edit forms:
assert_tag(:input, :attributes => {:type => :text, :id => "part_reference", :name => "part[reference]"}) - Run the test. Test fails.
- Add in the code for the form:
<p> <b>Reference</b><br /> <%= f.text_field :reference -%> </p>
- Run the test. Test passes.
- Add in the functional test to make sure the field is displayed in the show page:
assert_tag(:div, :attributes => {:class => 'property', :id => 'part_reference'}) - Run the test. Test fails.
- Add in the code for the show page:
<div id="property" id="part_reference"><b>Reference:</b> <%= @part.reference %></div> - Run the test. Test passes.
- Run through all of this in a browser, testing it yourself.
- Run the entire test suite.
- Commit to source control:
git add db/migrate/XXX_parts_add_reference.rb && git-commit -a - Deploy:
cap deploy:migrations - Check the live version, praying everything went OK.
Jesus fucking Christ. I have to specify the column in 4 different places: the migration, the model, the tests, and the view. Absolutely unacceptable. If I have to change the name of the column from "reference" to "part_number", it would be like performing an appendectomy. Putting it in in the first place requires 21 discrete steps. Just to add in one stinking column? Why in the hell can't it be four?
- Write the code:
shows :reference, :required => true, :size => 40 - Test.
- Commit.
- Deploy.
Now I know what you're saying: "That's magical web-app candyland! There's no way we'll ever get to that level! Even if we could, we wouldn't want to!" Bullshit. I think it would be fucking Stellar if someone came out with a web app framework that distilled development down to this tight cycle. Write one line of code. Test. Commit. Deploy. Four steps. That's all you need.
Stay tuned...