Is there are reason all the RoR tutorials use the hash idiom for active records, ie @record["fieldname"], when @record.fieldname is cleaner [and I expect faster?] ? Also, most of the tutorials use double quoted "names" which invokes the ruby enhanced string parser, as opposed to single quoted ''names'' which I expect would also be faster? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Wednesday, March 23, 2005, 9:30:03 AM, Neville wrote:> RoR Idiom QuestionsIs there are reason all the RoR tutorials use > the hash idiom for active records, ie @record["fieldname"], when > @record.fieldname is cleaner [and I expect faster?] ?The data is probably generated into a hash at a lower level. To make it available through accessors would probably necessitate the construction of another object, which is a performance hit, and one which is incurred whether the data is used or not.> Also, most of the tutorials use double quoted "names" which > invokes the ruby enhanced string parser, as opposed to single quoted > ''names'' which I expect would also be faster?That general issue was investigated on ruby-talk a year or so ago, and extensive benchmarks showed practically no difference in performance between "this" and ''this'', IIRC. Cheers, Gavin
> The data is probably generated into a hash at a lower level. To make > it available through accessors would probably necessitate the > construction of another object, which is a performance hit, and one > which is incurred whether the data is used or not.Not really, the method calls get translated to the same things one way or another. The [] accessors were originally created to allow you to access field names which are ruby reserved words, i.e. if you have a db field named "class", "def", "end", then calling foo.class doesn''t give you the expected results. Regards, -- Dave Steinberg http://www.geekisp.com/ http://www.steinbergcomputing.com/