See the Ruby feature request, in particular matz's comment.
When this feature was on the roadmap for Ruby 3, this cop made sense to me by default to help make sure that I would be able to reduce the pain in upgrading. However, it's now off the roadmap, so I'm not sure that this cop makes sense as something to be enabled by default at this point.
Perhaps I'm missing something else that can be gained by using frozen string literals, other than the intent of being ready for Ruby 3? I'm debating disabling this on my new projects, but it's been 6 months since the decision was made to remove the planned functionality from Ruby 3 and yet it remains a default cop across several Rubocop releases.
Perhaps I'm missing something else that can be gained by using frozen string literals, other than the intent of being ready for Ruby 3?
Frozen string literals reduce object allocations because Ruby doesn't allocate the same content in a new string object each time the literal is encountered. There is only one instance of that String.
There were a few years when folks were sprinkling .freeze calls on all the string literals for the performance benefits. The magic comment is preferable for readability.
Indeed. We might consider moving this cop to rubocop-performance, though, if there's no chance that this will become the default in Ruby at some point (e.g. Ruby 4, etc).
As far as I asked Matz a few months ago (RubyKaigi 2019), it was abandoned to default the frozen string literals in Ruby 3, but Matz seems to be thinking about an opportunity to default the frozen string literals in the future.
Also, frozen string literals has been introduced to libraries managed by the Ruby developers team (CSV, Psych, WEBrick, and others). https://github.com/ruby
I think it is better to see the future trends. And I think that this cop is suitable for style department now.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.
Most helpful comment
Indeed. We might consider moving this cop to
rubocop-performance, though, if there's no chance that this will become the default in Ruby at some point (e.g. Ruby 4, etc).