Kent Dahl wrote:

> George Ogata wrote:
>> which suggests there isn't really any practical difference (if my tests 
are
>> valid).  Actually, unless there are cases where '...' is noticably 
quicker,
>> perhaps it'd be more convenient to just make '...' and "..." identical (a
>> la python)?
> 
> But they aren't identical.
> "..." allows alot of string interpolation, such as #{variables} and a
> ton of backslash sequences.
> '...' is alot more restrictive, and only has a few backslash sequences.
> (And is therefore faster for the interpreter to interpret.)
> 

I know they're not identical, hence I was suggesting making both mean 
"...".  It wouldn't be backward compatible, though, so I'm not expecting it.

> IMHO, if there is more than one way to do something, there should be a
> reason. Now, your loop isn't very helpful since it doesn't DO all that
> much. (The "..." vs '...' difference only occurs once, at
> interpretation.)

Aha.  Critical.

> However, once you have alot of code, a lot of string
> constants, any string who doesn't need to be checked for interpolation,
> should use the '...'. It also makes it easier to write these strings,
> since you don't have to take into account a zillion things that need to
> be escaped.
> 

Zillion?  Only backslashes and #{...} constructs, no?  Neither strike me as 
being common (except backslashes in the Windows world).  There's still the 
%{} construct too.

> I tried two other tests:
> 500000.times{ eval "'hi'" } # str1.rb
> 500000.times{ eval '"hi"' } # str2.rb
> 
> With ruby 1.7.2 (2002-07-13) [i686-linux], there hardly was a difference
> 
> $ time ./str1.rb; time ./str2.rb
> 6.57user 0.05system 0:06.62elapsed 99%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (233major+2845minor)pagefaults 0swaps
> 6.55user 0.05system 0:06.59elapsed 100%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (233major+2845minor)pagefaults 0swaps
> 
> but with ruby 1.6.6 (2001-12-26) [i586-linux-gnu]
> 
> $ time ./str1.rb; time ./str2.rb
> 3.59user 0.01system 0:03.60elapsed 100%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (236major+260minor)pagefaults 0swaps
> 4.84user 0.03system 0:04.88elapsed 99%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (237major+2099minor)pagefaults 0swaps
> 
> Ugh, was 1.7.2 slower or does it just look like it? Anyway, I'm sticking
> with my original intention, which is '...' whenever possible, and "..."
> when you need to be able to shoot yourself in the foot :-)
> 

I find I shoot myself in the foot with '...' more than "...".  I might have 
a boring string, and so use '...', but then add a #{...} or \n or something 
in there, and forget to change the quotes.  Maybe the rule is: "..."  when 
there's any conceivable reason you might want to escape something in the 
future, and '...' for short, simple strings that you'll never touch again.  
Problem is putting in all that effort to hold down the shift key...

1.7's slower for me too.  And the difference between 1.6.7 and 1.7.2 is 
much bigger than between using '...' and "...".