Comment by teddyh
3 days ago
TIL that Ruby has mutable strings, and (until the announced change) even had them mutable by default (and the change only affects literal strings; non-literal strings are still mutable). Python has always only ever had immutable strings.
In Ruby you tend to use :symbol for small immutable strings
<< is inplace append operator for strings/arrays, while + is used to make copy. So += will make new string & rebind variable
I’ll just kill the comment. It said Symbol isn’t garbage collected. It has been since 2.2 and I wasn’t aware. Sorry.
Good reminder that anyone can go on the internet, just say stuff, and be wrong.
Symbols have been GCed since CRuby 2.2 https://bugs.ruby-lang.org/issues/9634
3 replies →
dynamically created symbols have been garbage collected for almost 10 years
3 replies →
We have mutable default arguments in Python (https://docs.python-guide.org/writing/gotchas/#mutable-defau...), by default too, though.
Not if they are strings, which is what this article is about.
Strings are going to keep being mutable by default. Only strings created by string literals won't be.
Thanks for the clarification! I have adjusted my wording.
Strings will still be mutable by default after the change which only makes string literals always frozen (which has been a file-level opt-in for a while.)
just dont ask about unicode
Unicode support in Ruby has been great since the beginning.
It's a bit weirder than that, in my opinion. Ruby didn't really gain "unicode support" in the sense we mean it today until 1.9.
Before that, Ruby did "support encodings" in a sense, but a lot of the APIs were byte oriented. It was awkward in general.
https://web.archive.org/web/20180331093051/http://graysoftin...
No, it was not great during 1.x times. But it has been fairly good since 2.0
1 reply →
Only if you count 1.9.2 as the beginning. What is being talked about is Unicode by default and maybe Unicode tooling (i.e. can correctly iterate over emojis and not just bytes)
right it was the python string transition i was talking about
Cool, good for you! I learned this in 2005.
Cool, good for you!