From: Greg Willits Date: 2012-04-21T01:39:47+09:00 Subject: Re: When are numbers NOT Magic? Example. Robert Klemme wrote in post #1057330: > On Thu, Apr 19, 2012 at 7:30 AM, Greg Willits > wrote: >> measurement technology and accuracy. Changing one value's precision >> string with thousands separators and with a specified precision. >> >> <%= float_as_thousands_with_precision(watts, 2) -%> >> >> >> I contend, those are NOT magic numbers. > > Certainly not. > >> Using the above definitions (and others I found like them), such numbers >> do not need constants because: >> -- each number is a single instance (no redundancy) >> -- each number is independent from the other (no shared cause & effect >> on precision) >> -- each number's purpose is very clear from from both the function name >> and argument name (no need to clarify purpose) > > But a constant's name goes a long way in documenting the meaning. Generically, I agree that's a good purpose for a constant, but in this case, it seems to me that <%= float_as_thousands_with_precision(watts, PRECISION_OF_WATTS) -%> isn't any clearer or better documented than <%= float_as_thousands_with_precision(watts, 2) -%> I think that's the crux of what I see. To me, the latter can't really be improved upon. It can be different, but is the extra code really adding value? Your FORMATS idea is interesting (and useful for a repeatedly used value), but in the end isn't it a variation on a list of constants? Anyway, thanks for your comments. I appreciate your taking the time to noodle on my epistle. -- gw -- Posted via http://www.ruby-forum.com/.