I don’t like writing validations, it feels like busy work. So if I do
them first, I drag my feet on the start of a project, if I do them last
I drag my feet at the end.
I think the proper way is to do them first. That way you have a solid
model to play with in your controllers and views, and you don’t have to
worry about the funny errors about nils here and there. It’ll force
you to do things correctly.
I’m writing a blog post on validation in Rails, and I would like to get
some opinions on when is the best time to write validation code?
My tendency is to save them till last, but I know many people write them
first thing. Any thoughts on when it is best to do this?
I tend to add validations as part of my approach to TDD. Once I have a
need
to restrict values I write a test or tests for it, include the
validation
and then move on.
This way it stays out of my way until I need it, and I don’t need to do
all
the validations up front, or leave them until the end. They just become
part of the flow.
I don’t like writing validations, it feels like busy work. So if I do
them first, I drag my feet on the start of a project, if I do them last
I drag my feet at the end.
I think the proper way is to do them first. That way you have a solid
model to play with in your controllers and views, and you don’t have to
worry about the funny errors about nils here and there. It’ll force
you to do things correctly.