From: Dave Aronson Date: 2012-02-07T01:29:39+09:00 Subject: Re: Please help me find the error in my logical OR On Sat, Feb 4, 2012 at 21:30, h4y4shi 13bladex wrote: > I think the error is in the following code. I think it would be a lot easier to fix if it weren't depending on several things with very similar names. As has been suggested before, you can make this MUCH shorter *and clearer* (the two are not the same, witness Perl) by simply putting them in an array instead of a bunch of vars. Then you can sum them and subtract out the lowest, or sort them and omit the lowest in your summing, or various other approaches. To take it to a higher level: any time you find yourself declaring a series of variables with very similar names, especially just varying by some tag that exists only to make the names different, STOP! You are almost certainly doing something that would be much better done with an array. (Or possibly a hash.) You can almost always achieve the same effect, much more simply, reliably, flexibly, and clearly, by iterating over an array or hash, than by doing essentially the same code for each of a bunch of very similar variables. For example, in your specific case, if you needed to accomodate one more number, your current approach would require a boatload of tiny little code changes and a couple of additions. Each change, addition, or even deletion, introduces an opportunity for bugs to leak in. Using an array... no changes, except in initially populating it. To take it to an even higher level: don't just think about what will produce the right answer, right now. Also take into account what will best communicate the intent to a future reader, and other factors that will make future changes easier and more robust. That is one of the things that separates a "software engineer" from a mere "code monkey". > Attachments: > http://www.ruby-forum.com/attachment/6951/rpgv3.rb We who read this as an email list can't get at that. If you want more eyes on it, put it somewhere public. (Or if it's *very* short, just include it in the body.) -Dave -- Dave Aronson:  Available Cleared Ruby on Rails Freelancer (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com