[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Symbols and non-strings in string interpolation?
From:       Matthew Kerwin <matthew () kerwin ! net ! au>
Date:       2017-07-04 23:20:19
Message-ID: CACweHNDNAePGBPY8V7wwadHe+zODcLU3DOUjqw+HXs+h2wEpGQ () mail ! gmail ! com
[Download RAW message or body]

On 5 July 2017 at 08:14, Eric Wong <e@80x24.org> wrote:
> Hey, just wondering if this is a common thing in normal Ruby
> code.  I think it's somewhat common to use symbols and integers
> in string interpolation; at least I seem to do it :)
>
> Anyways, I just posted a new patch to ruby-core and am wondering
> if there's more Rubyists here which might find it useful for 2.5:
>
> https://bugs.ruby-lang.org/issues/13715
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/81905
> https://public-inbox.org/ruby-core/redmine.issue-13715.20170704220431.8a8b5cc25b8ecd8e@ruby-lang.org/
>
> Even without the special case for Symbols, the inline caching
> seems to be a decent win for other types.
>

Yes, definitely.  As a general rule, if I have all the data ahead of
time I always* use interpolation to create strings.  If the data is
streamed then I'll choose how I stringify them based on other factors
(shared references, frozenness, number of elements, likelihood and
impact of reallocations vs whole new allocations, readability, etc.)

  * except when I don't.

It doesn't help that `<<` and `+` both need me to explicitly `.to_s`
any parameter that doesn't respond_to? :to_str (a feature for bug
detection, but a hindrance for writing quickly)

Optimisation is never my primary driver when writing Ruby (except for
broad strokes, like choosing appropriate data structures and
algorithms) but if you can make my code run faster then I certainly
won't complain.

Cheers
-- 
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic