From: Jesse Jones Date: 2004-08-04T21:11:30+09:00 Subject: Re: Macros in Ruby In article <9e7db91104080322005735a859@mail.gmail.com>, Austin Ziegler wrote: > On Wed, 4 Aug 2004 08:26:32 +0900, Jesse Jones > wrote: > > percent-case > > 0.75 case > > normal_hit > > end > > > > 0.20 case > > critical_hit > > end > > > > otherwise > > kill_foe > > end > > end > > I'm sorry, but I don't see how this is more readable than: > > case hit_roll > when (0.0 .. 0.75) > normal_hit > when (0.75 .. 0.95) > critical_hit > else > kill_foe > end > end A macro (or some clever code like Joel's) is better in two ways: 1) It's much easier to glance at numbers like 0.75 and 0.20 and figure out the relative weighting. For me at least, it's a fair amount harder to subtract two sets of numbers and compare them. Of course, you could add comments listing the percentages, but it's always preferable to rewrite the code so that it doesn't need such comments. 2) Adding new cases is harder if you have to deal with ranges. Not a lot harder to be sure, but somewhat tedious. Also note that this wasn't intended to be the last word in the utility of macros. It was merely one of the simpler app specific examples I could think of. -- Jesse