Earlier quoted context omitted.
Java too. Rust has only 99 string types, some of those are immutable also.
Rust the language has one string type: &str The standard library also has String, CString, CStr, OsString, and OsStr. The latter four are for niche situations. 99.9% of the time, it's similar to Java: &str is Java's String, String is Java's StringBuffer/StringBuilder.
Ruby 3.4 frozen string literals: What Rails developers need to know
101–110 of 131 posts
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#102Earlier quoted context omitted.
Rust the language has one string type: &str The standard library also has String, CString, CStr, OsString, and OsStr. The latter four are for niche situations. 99.9% of the time, it's similar to Java: &str is Java's String, String is Java's StringBuffer/StringBuilder.
There is also &mut str. The nice thing about Rust is that the same memory area can be used as a "StringBuilder" with &mut str, and then as a "String" with &str. Once you have a &str reference, Rust statically guarantees that no one else cam mutate it.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#103Earlier quoted context omitted.
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.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#104Has anyone actually benchmarked the use of frozen string literals? I feel like this is one of those micro-optimizations that everyone does, but they're probably accomplishing a diminishingly small performance improvement, while making the codebase less readable. On net, a negative.
Yes: https://bugs.ruby-lang.org/issues/20205#note-34
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#105Earlier quoted context omitted.
Also JavaScript.
Java too. Rust has only 99 string types, some of those are immutable also.
String
&str
&mut str
&'static str
etc.
These are just the language semantics.The other string types are non-Rust strings. Filesystem, C strings, etc. You only deal with them in dealing with specific OS and binding interfaces.
95% of the time you'll just be using String.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#106Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#107Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#108Well it is not quite a mutable vs immutable strings war, nor Ruby being late to the party or something like that. The move is so we can avoid allocating a string each we declare and use it since it will be frozen by default. It is a big optimization for GC mainly. Before we had to do such optimization by hand if we intend not to modify it: # before def my_method do_stuff_with("My String") # 1 allocation at each call…
It is sorta late to the party. Common Lisp has similar with regards to how lists are done. Specifically, it is not uncommon to make a static list like `'(1 2 3)`. Doing this, however, has implications on what operations you can do on the data elsewhere. I say sorta late to the party, as I think it is more than fair to say there was not much of a party that folks were interested in in the lisp world. :D
Oh, I think I see some nameless person I know over there. Well-met Lisper, but goodbye!
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#109Earlier quoted context omitted.
Java too. Rust has only 99 string types, some of those are immutable also.
All of those languages except JavaScript have mutable strings; they just have different names and API shapes. Python has io.StringIO, Java has StringBuilder, Rust has String. (JavaScript has less need for this because JavaScript strings are ropes in most widely used implementations, reducing the overhead of concatenation, though the language spec doesn't require this.)
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#110Earlier quoted context omitted.
> They're just not especially performant What? Mutable strings are more performant generally. Sometimes immutability allows you to use high level algorithms that provide better performance, but most code doesn't take advantage of that.
Not in general. Immutable strings can be deduplicated, leading to a different performance tradeoff that is often quite good. This is mentioned in TFA.