From: Alan Burch Date: 2006-03-11T15:40:47+09:00 Subject: Re: Help me understand why the Ruby block is slower than wit Stephen Waits wrote: > On Mar 10, 2006, at 4:08 PM, Alan Burch wrote: > >> >> Not measurably faster than the first one, but seems better and more >> Ruby >> like to me. > > I'm curious why you see it so? Personally, seems less Ruby-like to me. > > --Steve Steve: Let me be the first to say that I certainly don't understand Ruby idiom yet, that's why I'm using the word seems in my earlier reply. I may feel quite different about the newer code in a few days... I like it better because it's more succinct as there're fewer intermediate steps and because I can see what it's doing quite quickly. My code looks a bit like that K&R C that I learned in the early 80s. You can even see my OTB style and probably guess that I still use vi(m) :). I'd rather learn the Ruby idiom and that's part of what I was asking here. Learning that 'puts' doesn't throw the EOF as I was expecting, was an important lesson and so was the rite of passage that Mr Wright pointed out. The Ruby language feels good to me, and I'd like it to feel as comfortable as C does to me, so thanks again for all the kind help. Bill: Thanks for adding a bit more to reading it all in and processing script. I like code that's quite readable and will take that over code that's faster but not so readable in any case where I can get away with it. That said, I still really like the regex that checks to see if the string is unique. No conversion to an array and no need to re-check the size of it all so the current piece of code I like best is: f= File.open("./words").each { |w| puts w if w.size == 11 && w !~ /(.).*\1/ } It's also the fastest that I've tested. I would, however, add a comment to explain what the regex does so I wouldn't have to stare at it for a minute or two to figure it out after a few months away. Alan -- Posted via http://www.ruby-forum.com/.