Hacker News new | ask | show | jobs
by simfoo 3027 days ago
str and String? That naming is horrible. string_view is a much better choice
3 comments

1. string_view makes for much more verbose code when it's the more common version.

2. string_view makes no sense when many str are not actually views into strings but either static data or "cast" bytes.

3. string_view makes no sense when str is the basic builtin type.

Renaming String to something like StrBuf might have made sense, but it's not like it would have been any clearer, people get confused by Path/PathBuf all the same if not more so.

It's certainly confusing at first, but the terse naming of "str" is appreciated once you've internalized the difference. "str" is, in most projects I've seen, appears more often in source than "String".
I completely agree.

Path/PathBuf have better names, but the distinction still isn't immediately obvious.

String/str is the cause of so much confusion.

I often joke that str/StrBuf is my one wish for a Rust 2.0, but 2.0 will never happen.

This confusion is why we reorganized the book to talk about String and &str very early on, and use them to teach ownership and borrowing.

It took me like 2 seconds to learn it and haven't been confused since. So... maybe I'm just a grade A genius.