Hey Tom, On Thu, Mar 18, 2010 at 3:20 AM, trans <[email protected]> wrote: > Song.select do |s| > s.artist =~ /Mary/ & s.year > '1980' > end
The problem with this syntax, and to me the major problem with this technique, is illustrated by the fact that the example as you've shown here doesn't work. The & operator actually has the wrong precedence for this to work and you have to write this: Song.select do |s| (s.artist =~ /Mary/) & (s.year > '1980') end You could say that this is more readable and good practice etc., but in the end it is just plain annoying and easy to forget. Also, having to use &, | and ~ instead of &&, || and ! is a big enough problem as you'll have a tendency to write the actual boolean operators and doing so can lead to weird bugs. I've actually considered a version that is a lot smarter and can work with &&, || and !, but I've never gotten around to implementing it. The idea was to treat the block as a black box and determine its behavior by feeding it different inputs and registering the output. Karnaugh maps would then allow you to find a matching expression. In the above example with 2 inputs (s.artist and s.year) you'd have to test just 4 combinations, but in general with n inputs you need to test 2**n combinations, so in practice it can be impractical. Plus it will never be perfectly general, and it cannot handle closures. Nevertheless, I would be interested in seeing this implemented to see how usable it is in practice. If you are interested in giving it a try, I'll see if I can get the presentation back online because we moved our servers to a different hosting company and the link is now broken. You can always make it an extension to DataMapper without the need for it to be in the official distribution; it can just translate to regular DataMapper syntax. Peter -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
