8 ms·
Rust strings are difficult for others coming from statically typed and low level languages as well. It’s one of the types programmers will most often encounter
by lumost 4y ago
Rust strings are difficult for others coming from statically typed and low level languages as well.
It’s one of the types programmers will most often encounter, and yet it’s one of the most obtuse topics within rust.
- k__ 4y agoI remember strings being "not so easy" in C/C++ too.
- oconnor663 4y agoI think the big differences are that copying and reference taking are automatic and invisible in C++. So a lot of APIs taking string or string& will "just work" for the beginners, and you can delay the part where you talk about how different those things are. This sounds like a minor difference, but I've met lots of developers who do meaningful work in C++ but who don't know what a copy constructor is. I get the impression that there's an enormous difference between being a C++ "user" vs a "library writer", because there's so much automatic stuff happing under the covers. Rust tends to have a bit less invisible complexity, I think, but some of that difference is just making the complexity visible (like reference taking), which effectively frontloads it onto beginners. It's a tough tradeoff.
- rocqua 4y agoI occasionally port my C code to C++ just for more ergonomic strings.
- jokethrowaway 4y agoAfter haskell strings, rust strings actually felt reasonable
- eru 4y agoAlas, Haskell's built-in strings are horrible. Anything serious would use Data.Text or Data.Bytestring (depending on the situation). Unfortunately, most of the language and libraries got written before reasonable strings were available. So you still see lots of things taking linked-list strings.
- lumost 4y agoRust could probably benefit from a collections style reintroduction of String and maybe one or two other common data structures. To simplify the language. It’s not so much a language problem as a rough implementation of a hyper common data structure.