James Britt
8/19/2008 5:21:00 PM
Michael Morin wrote:
> Roger Pack wrote:
>> Typically AR basically stinks to type in--it is way too wordy, and, for
>> lack of a better term, SQL like.
>> klass.find :all, :conditions => ["name LIKE '%?'", 'fred']
I see that as a plus, not a minus. SQL is well-known, so if you need to
know how to do something there a many examples and resources.
>>
>> This library condenses that to be a little more englishy, by allowing
>> hashed parameters that are parsed for meaning, ex:
>>
>> klass.where 'name starts with' => 'fred'
>>
>> This reads better, is much faster, has support for regex, case
>> sensitivity, etc. without the pain of SQL.
Pain of SQL? Anyone writing code, and writing code that interacts with
a database, owes it to themselves (and their clients if they are coding
for $) to learn at least basic SQL and know where to look to learn more.
It's a DSL meant for relational data. For the most part it is not
hard, and it gives you the power to write compact, efficient queries.
>
> That's interesting, but I have to question the code:payoff ratio. Most
> ActiveRecord usage doesn't have particularly diverse queries. These
> queries can be easily and simply hidden away in single-line class
> methods to give them meaningful mnemonics like "name_starts_with". Using
> class methods is transparent, trivial and not limited by the features of
> your library.
>
> English is also a very subjective language. What you've done is limited
> users to a tiny, strict subset of English which is more or less the same
> as doing something like where :title => [ :starts_with, 'Something' ].
> That would require a lot less code and zero parsing.
Attempts to allow code that is "English-like" tend to come off as the
worst of both worlds. You lose the compactness and precision of code,
while never really getting the fluid expressiveness of natural language.
It tends to look and read as clunky.
I'd much rather have code that reads like Ruby but allows for raw SQL
when needed (Sequel, as a prime example, or Og), rather then code that
doesn't quite read as code, and doesn't quite read as English either.
And if you're going to write DB apps, then geek up and just learn the SQL.
--
James Britt
www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff