[clue-tech] increment weather

David L. Anselmi anselmi at anselmi.us
Tue Feb 23 18:59:27 MST 2010


Brian Gibson wrote:
>> I wonder whether in-loop mods are a good idea.
>
> In general or this specific case?

In general.

> Iterators are awesome.  Check out: http://www.skorks.com/2009/09/a-wealth-of-ruby-loops-and-iterators/ and http://billsix.blogspot.com/2008/03/functional-collection-patterns-in-ruby.html for Ruby examples.  In other words, even with flow control, it's best to pick the right tool for the job.

Sure, and much better than just having a counter to increment and having to use that as an index 
into your list.  That's what Willson was doing (though he wanted a counter in this case).

But you missed my point, I think.  Given that you have a counter, I think it's error prone to decide 
part-way through your loop to change the way you're counting.  E.g., you put logic in the loop so 
that at the top your counter goes like:

1 2 3 4 5
7 8
3 5 7 9
9 7 5 3
...

Or in Willson's case:

1 2 3 4
7 8 9 10

You can certainly make it do things like that but it will be error-prone compared to a simple loop.
If you decide that that's what you really need then you have to decide to test it extra carefully.

Dave


More information about the clue-tech mailing list