From: Austin Ziegler Date: 2004-08-05T00:12:11+09:00 Subject: Re: Macros in Ruby On Wed, 4 Aug 2004 21:11:30 +0900, Jesse Jones wrote: > 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. Hmm. I disagree. I mean, it's better to deal with code like Joel's (or my Attacker class that I presented, which even makes sure you can't go over 100%), because then you've treated the cases as closures and objectified the whole thing, so that you don't have to do the numbers, but basically (0 .. 75) says very clearly that you'll accept any value in that range. It's harder to be dynamic, but you'll note that my Attacker class (the second possibility in the email to which you responded) makes that easy and still uses the range comparison. I don't think that a domain-specific language is needed for that case. The only situation I can think of that came up recently was the one where someone wanted to introduce the a new operator ":="; that could be handled with a domain-specific language with ease. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca