Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Well thats great, guess I have carried that baggage with me as misinformation for years now.


One 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.


Same here. Turns out writing too much code for RPG Maker XP when young ruins one’s perception of Ruby forever


dynamically created symbols have been garbage collected for almost 10 years


Yeah I am a moron. Updated.


No. A moron would refuse to learn. You are open minded and humble.


Thank you stranger <3


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


So for at least 12 years then. 2.0 was released in 2013.


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!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: