This post originated from an RSS feed registered with Ruby Buzz
by David Heinemeier Hansson.
Original Post: Validate models using code, not annotations
Feed Title: Loud Thinking
Feed URL: http://feeds.feedburner.com/LoudThinking
Feed Description: All about the full-stack, web-framework Rails for Ruby and on putting it to good effect with Basecamp
Berin Loritsch is thinking about how to validate his domain models in Java. He's on the right track with his intention to shun the XML morass so commonly sought by the J-people, but unfortunately his ambitions stop short. He seems to be content with merely annotating his models with the validation rules instead of actually embedding them in code.
If he were using Rails, he'd be able to enjoy specifying validation rules using actual code in his Active Record objects. The following is not even a mock-up, I literally yanked part of the Account model in that next project I'm working on:
To me, this is beautiful. Programming poetry. Each method call reads like a sentence. "Account validates acceptance of terms of service on create". How can you not love that?
So please, aim higher. Annotations are a work-around for type system thats holding you back. Let it go. We'll be happy to help you transition out of the Sun and into the shade. Come join us in the Ruby on Rails community.