From: dblack@... Date: 2006-03-18T02:01:59+09:00 Subject: Re: Card tricks with Ruby Hi -- On Sat, 18 Mar 2006, Stephen Waits wrote: > Matthew Moss wrote: >> > [snip] > > Well, it's definitely one of the (very) few things that has bothered me about > Ruby. For example: > > A Rubyist might argue that this is more error prone: > > for(int i=0;i<10;i++) > > than this: > > 10.times > > Which is a valid argument, and the result is elegant. And, we see stuff like > this throughout Ruby. As Why's guide says often, read the code aloud. > > So yes, .. vs ... really bugs me. While they are convenient operators, I > also see them as too error prone to fit in Ruby. > > As an earlier mentioned example, when I've taught Ruby, I always feel like I > have to wave the red flags when I talk about ranges. > >> Unit testing could catch some errors, but I do agree if something >> reasonably simple could replace it syntax-wise, it might be a tad >> better. What that something simple is, I don't know... The simplest >> solution would be to use mathematical notation, but that would be a >> pita for the compiler to parse: [0..x) > > Yah, [x..y], [x..y), (x..y], (x..y) would be sweetness. It's slightly less > error-prone IMO since it's following a common (math) notation. Still, maybe > not perfect. Can you really stand to look at that? It gives me the same feeling as putting my shoes on the wrong feet :-) I'm not sure what it is about the range operators that bothers you. Are you finding it hard to remember which is which? My way of remembering is: every range is the same width, in relation to the operators. Since the ... operator is wider, the end-point gets pushed outside the range: v v a..b a...b ^ ^ So b is off the map in the second one. This is of course a schematic way to view it (not proportional to the contents of the range), but I found it helpful and maybe you will. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black