From: Chad Perrin Date: 2007-07-11T02:14:22+09:00 Subject: Re: Beautiful Code : Pity he didn't ask here... On Tue, Jul 10, 2007 at 11:47:26PM +0900, Tim Bray wrote: > On Jul 9, 2007, at 5:15 PM, John Carter wrote: > > >In Example 4.3 he has... > >1 counts = {} > >2 counts.default = 0 > > > >Personally I prefer... > > counts = Hash.new(0) > > or > > counts = Hash.new{|hash,key| hash[key]=0} > >buts that's personal preference I guess. > > Gosh, I think I totally disagree on readability grounds. Actually, I think this: counts = Hash.new(0) . . . is perfectly readable, and a bit more elegant than the two-line version from "Example 4.3". On the other hand, this bit looks pretty ugly to me: counts = Hash.new{|hash,key| hash[key]=0]} . . . especially since it looks like someone is afraid he has a limited number of space characters to use, and doesn't want to run out. Even with some spaces added to it, though, it's not as pretty and readable. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] Larry Wall: "A script is what you give the actors. A program is what you give the audience."