Earlier 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.
Ruby 3.4 frozen string literals: What Rails developers need to know
111–120 of 131 posts
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#112Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#113Earlier quoted context omitted.
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.
You can't really do anything useful with a `&mut str`. For example, you can't change the length of the string or any characters in the string (without unsafe code). The latter is perhaps surprising, but it's because strings in Rust are always UTF-8, so changing a logical character could imply changing the length of the string, and changing a byte could result in invalid UTF-8.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#114Earlier 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.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#115Btw, OCaml also transitioned from read-write Strings to read-only Strings, and Buffer to be that read-write string. It was introduced in 4.02 released September 2014. I recall it was a bit bumpy, but not all that rough in the end. I suppose static type checking helps here to find all the ways how it could be used. There was a switch to allow running old code (to make strings and buffers interchangeable).
Nitpick: `bytes` is the read-write string, `Buffer` is the StringBuilder-like.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#116Earlier quoted context omitted.
I would actually say it’s the opposite in this case: it’s extremely common in scripting languages for strings to be immutable, mutable strings are usually only available in lower level languages. I’m very surprised Ruby had this feature at all.
Common Lisp and Smalltalk have mutable strings, I think. So it’s not too surprising that ruby does too, since it was pretty heavily influenced by these languages.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#117Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#118Earlier 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.
99.9% of the time rust has 1 string type. The other 0.1% of the time it has 99, got it.
Re: Ruby 3.4 frozen string literals: What Rails developers need to know
#119So I sometimes wonder why JIT isn't used as a motivation to move / remove features. Basically if you want JIT to work, your code has to be x ready or without feature x. So if you still want those performance improvements you will have to move forward.