rails/rails — comment on commit 12be0a59856d4f92a85c479843e296342be47789
File:  line 0
By tenderlove:

You can't prevent people from doing stupid things. They can get around the freeze with const_set, so there is no point. The freeze will *possibly* prevent extra objects, but that's about it. I have yet to see conclusive proof (outside of roflbenchmarks) that freezing the works will reduce overall memory and runtime.

When all our algorithms are constant time, and caching is done 100% correctly, we should revisit optimizations like this.

--
Aaron Patterson
http://tenderlovemaking.com/

On Dec 7, 2011, at 12:43 PM, Prem Sichanugrist wrote:

> Correct me if I'm wrong, but I think it is to make the string immutable, as we wouldn't want someone to play around with that constant right?
>
> ```
> irb(main):001:0> FOO = 'foo'
> => "foo"
> irb(main):002:0> FOO.sub!(/.+/, 'bar')
> => "bar"
> irb(main):003:0> FOO
> => "bar"
> irb(main):004:0> FOO.freeze
> => "bar"
> irb(main):005:0> FOO.sub!(/.+/, 'baz')
> TypeError: can't modify frozen string
> from (irb):5:in `sub!'
> from (irb):5
> ```
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/rails/rails/commit/12be0a59856d4f92a85c479843e296342be47789#commitcomment-777205