5 ms·
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 s
by teddyh 1y 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.
- llamataboot 1y agojust dont ask about unicode
- neallindsay 1y agoUnicode support in Ruby has been great since the beginning.
- yxhuvud 1y agoNo, it was not great during 1.x times. But it has been fairly good since 2.0
- WJW 1y agoSo for at least 12 years then. 2.0 was released in 2013.
- steveklabnik 1y agoIt'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://graysoftinc.com/character-encodings/bytes-and-characters-in-ruby-18 https://web.archive.org/web/20180331093051/http://graysoftin...
- llamataboot 1y agoright it was the python string transition i was talking about
- 0x457 1y agoOnly 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)
- thibaut_barrere 1y agoWe have mutable default arguments in Python (https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments https://docs.python-guide.org/writing/gotchas/#mutable-defau...), by default too, though.
- teddyh 1y agoNot if they are strings, which is what this article is about.
- skywhopper 1y agoCool, good for you! I learned this in 2005.
- WJW 1y agoCool, good for you!
- tangus 1y agoStrings are going to keep being mutable by default. Only strings created by string literals won't be.
- teddyh 1y agoThanks for the clarification! I have adjusted my wording.
- __s 1y agoIn 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
- corytheboyd 1y agoI’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.
- jashmatthews 1y agoSymbols have been GCed since CRuby 2.2 https://bugs.ruby-lang.org/issues/9634 https://bugs.ruby-lang.org/issues/9634
- corytheboyd 1y agoWell thats great, guess I have carried that baggage with me as misinformation for years now.
- hinkley 1y agoOne of the things I’ve said I would do and never did is create a set of test suites for as many facts about a language as I know and then run it for every new release to see what I need to unlearn. Most but not all of these were performance related. If it took a few days to run that’s fine. Major versions don’t come out that often.
- runeblaze 1y agoSame here. Turns out writing too much code for RPG Maker XP when young ruins one’s perception of Ruby forever
- zht 1y agodynamically created symbols have been garbage collected for almost 10 years
- dragonwriter 1y agoStrings 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.)