4 ms·
He's working too hard. You don't need all those type declarations. let a = "hello".to_string(); let b = "world".to_string(); let c = a + " " + &b;
by Animats 6y ago
He's working too hard. You don't need all those type declarations.
let a = "hello".to_string();
let b = "world".to_string();
let c = a + " " + &b;
println!("Sentence: {}", c);
It's a bit confusing that you need "&b". "+" was defined as String + &str, which is somewhat confusing but convenient.
If you've been handling Unicode properly in other languages, then Rust strings seem easy in comparison.
Yes. C is awful. C++ is still sometimes UTF-16. C#/.net is still mostly UTF-16. Windows is still partly in the UTF-16 era. So is Java. So is Javascript. Python 2 came in 2-byte and 4-byte versions of Unicode. The UTF-16 systems use a "surrogate pair" kludge to deal with characters above 2^16. CPython 3 has 1, 2, and 4 byte Unicode, and switches dynamically, although the user does not see that.
Linux and Rust are pretty much UTF-8 everywhere now, but everyone else hasn't killed off the legacy stuff yet.
- brundolf 6y agoThe type declarations are there for maximum clarity, since the inferred types may not be obvious to the target audience
- jdmichal 6y agoYes, please. One of my biggest peeves are posts that are meant to be educational, but yet don't define the types used for variables nor define the namespace / package they are from. Java posts are rife with the latter, and I'm really not looking forward to the `var` keyword making the former a thing too. And quite a few get bonus points for doing such on types that require a new dependency -- but good luck figuring out which dependency without knowing the dependency name nor the package name of the class!
- mywittyname 6y agoYou did it right, IMHO. The parent comment just confuses me while your article was quite clear.