I''ve seen a few inconsistencies both in AWDR and the rails API docs, but the de facto standard is: :controller => ''foo'', :action => ''bar'' I wonder what the reason is for supplying foo and bar as strings instead of symbols? One thing I can think of is that with many arguments you probably increase the readability compared to: :controller => :bar, :action => :bar I also wonder if any of the benchmark lovers have run tests on double vs single quotes? I remember from back when I coded PHP that you could get a noticable loss in performance from using double quotes (when not necessary of course).
greendale wrote:> I''ve seen a few inconsistencies both in AWDR and the rails API docs, but > the de facto standard is: > > :controller => ''foo'', :action => ''bar'' > > I wonder what the reason is for supplying foo and bar as strings instead > of symbols? One thing I can think of is that with many arguments you > probably increase the readability compared to: > > :controller => :bar, :action => :bar > > I also wonder if any of the benchmark lovers have run tests on double vs > single quotes? I remember from back when I coded PHP that you could get > a noticable loss in performance from using double quotes (when not > necessary of course).I''m really interested in this topic too, since i come from PHP, and there i use apostrophes when possible. -- Posted via http://www.ruby-forum.com/.
On 11/28/05, Rodrigo Alvarez <papipo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> greendale wrote: > > I''ve seen a few inconsistencies both in AWDR and the rails API docs, but > > the de facto standard is: > > > > :controller => ''foo'', :action => ''bar'' > > > > I wonder what the reason is for supplying foo and bar as strings instead > > of symbols? One thing I can think of is that with many arguments you > > probably increase the readability compared to: > > > > :controller => :bar, :action => :bar > > > > I also wonder if any of the benchmark lovers have run tests on double vs > > single quotes? I remember from back when I coded PHP that you could get > > a noticable loss in performance from using double quotes (when not > > necessary of course). > > I''m really interested in this topic too, since i come from PHP, and > there i use apostrophes when possible.Symbols are efficient strings. Anytime you use ''blah'' it creates a new string in memory. But, every copy of :blah is exactly the same. Kevin has a great article on this topic: http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols I believe that you can pass the action as a symbol, such as :action => :bar, but not controllers. There is the possibility of controllers having a path, such as :controller => ''admin/foo'' or :controller => ''/account''. The real reason I use symbols is it''s 1 less character to type, and textmate gives it this pretty color :) -- rick http://techno-weenie.net
Thanks. What about the double quotes vs. apostrophes? Do quotes increase memory usage or app performance? On 11/28/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 11/28/05, Rodrigo Alvarez <papipo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > greendale wrote: > > > I''ve seen a few inconsistencies both in AWDR and the rails API docs, > but > > > the de facto standard is: > > > > > > :controller => ''foo'', :action => ''bar'' > > > > > > I wonder what the reason is for supplying foo and bar as strings > instead > > > of symbols? One thing I can think of is that with many arguments you > > > probably increase the readability compared to: > > > > > > :controller => :bar, :action => :bar > > > > > > I also wonder if any of the benchmark lovers have run tests on double > vs > > > single quotes? I remember from back when I coded PHP that you could > get > > > a noticable loss in performance from using double quotes (when not > > > necessary of course). > > > > I''m really interested in this topic too, since i come from PHP, and > > there i use apostrophes when possible. > > Symbols are efficient strings. Anytime you use ''blah'' it creates a > new string in memory. But, every copy of :blah is exactly the same. > > Kevin has a great article on this topic: > http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols > > I believe that you can pass the action as a symbol, such as :action => > :bar, but not controllers. There is the possibility of controllers > having a path, such as :controller => ''admin/foo'' or :controller => > ''/account''. > > The real reason I use symbols is it''s 1 less character to type, and > textmate gives it this pretty color :) > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Monday 28 November 2005 17:42, Rick Olson wrote:> Symbols are efficient strings. Anytime you use ''blah'' it creates a > new string in memory. But, every copy of :blah is exactly the same.This is only true when symbols are used consistently. In Rails there are numerous places where conversion from strings to symbols or the other way around occur. Just search for stringify_keys and symbolize_keys. The same goes for Hash#with_indifferent_access. Therefore, I''m inclined to doubt that the use of symbols in its current state in Rails improves efficiency. Michael -- Michael Schuerig You can twist perceptions mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org Reality won''t budge http://www.schuerig.de/michael/ --Rush, Show Don''t Tell
Rodrigo Alvarez Fernández wrote:> Thanks. What about the double quotes vs. apostrophes? Do quotes increase > memory usage or app performance?I did a few very simple tests with the profiler, just looping through some string operations 100000 times, and I couldn''t find any difference at all in performance between single and double quotes. I did however learn that x = "#{str1}#{str2}" is about four times faster than x = str1 + str2> On 11/28/05, *Rick Olson* < technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > On 11/28/05, Rodrigo Alvarez < papipo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:papipo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > greendale wrote: > > > I''ve seen a few inconsistencies both in AWDR and the rails API > docs, but > > > the de facto standard is: > > > > > > :controller => ''foo'', :action => ''bar'' > > > > > > I wonder what the reason is for supplying foo and bar as strings > instead > > > of symbols? One thing I can think of is that with many arguments you > > > probably increase the readability compared to: > > > > > > :controller => :bar, :action => :bar > > > > > > I also wonder if any of the benchmark lovers have run tests on > double vs > > > single quotes? I remember from back when I coded PHP that you > could get > > > a noticable loss in performance from using double quotes (when not > > > necessary of course). > > > > I''m really interested in this topic too, since i come from PHP, and > > there i use apostrophes when possible. > > Symbols are efficient strings. Anytime you use ''blah'' it creates a > new string in memory. But, every copy of :blah is exactly the same. > > Kevin has a great article on this topic: > http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols > > I believe that you can pass the action as a symbol, such as :action => > :bar, but not controllers. There is the possibility of controllers > having a path, such as :controller => ''admin/foo'' or :controller => > ''/account''. > > The real reason I use symbols is it''s 1 less character to type, and > textmate gives it this pretty color :) > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org <mailto:Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails