This is based on his Ruby study notes made while he studied Ruby
himself,
from various online Ruby resources like tutorials, blogs and Ruby
documentation. A site I would definitely recommend for Ruby newbies.
One quick question in one of his examples he states that using single
quotes for strings is more efficient, why is this?
I believe the theory goes that using single quotes means that there is
no
interperlation required, and therefore less work for the interpereter.
Thus
faster.
This was discussed here a few of weeks ago, with some benchmarks that
seemed
to indicate that there
really isn’t much difference between the two.
I’m not sure that the thread ended up reaching a conclusion though.
I’m not sure that the thread ended up reaching a conclusion though.
No, it didn’t. The hypothesis was that the parser has a little easier
time with non-interpolated strings, and the benchmarks didn’t test that.
They had N.times { “blah blah” } when they should have had N.times {
eval ‘“blah blah”’ }.
That said, it’s hardly a reason to go for single quotes. I mean, the
quintessence of premature optimization dude. /That/ said, I think the
singles make less line noise.
I’m not sure that the thread ended up reaching a conclusion though.
No, it didn’t. The hypothesis was that the parser has a little
easier time with non-interpolated strings, and the benchmarks
didn’t test that. They had N.times { “blah blah” } when they should
have had N.times { eval ‘“blah blah”’ }.
I find the double quotes more intuitive, but it’s a microscopic
difference and probably has to do with my years of C and BASIC
(notwithstanding the years of Pascal and Fortran).
Seconded. Though recently, my fingers protest against my Java day job
where double-quotes are the only thing I hit Shift for. (I make heavy,
heavy abuse of autocomplete.)
I am developing a Ruby tutorial as well. I will be covering CGI
integration and database programming too. I will also try ti hit web
caching and cookies for web programmers.
singles make less line noise.
A common convention is to use single quotes unless there is
a reason to use double quotes. I sometimes follow that, but
frequently forget.
I find the double quotes more intuitive, but it’s a microscopic
difference and probably has to do with my years of C and BASIC
(notwithstanding the years of Pascal and Fortran).
Seconded. Though recently, my fingers protest against my Java day job
where double-quotes are the only thing I hit Shift for. (I make heavy,
heavy abuse of autocomplete.)
Seriously? What about common operators like “+”, “*”, “&&”, and “||”?
I don’t see how autocomplete would help with those.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.