rust-lang / book

The Rust Programming Language

Home Page:https://doc.rust-lang.org/book/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3.2 Data types: 'Rust’s char type is four bytes in size'

rillig opened this issue · comments

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • char
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • src/ch03-02-data-types.md

Description of the problem:
The text says:

Rust’s char type is four bytes in size

The wording 'four bytes' doesn't match the naming of Rust's integer types, which are measured in bits. A more consistent wording would be '32 bits'. The words 'four bytes' may also lead to wrong conclusions related to MySQL's utf8mb4 type.

Suggested fix:

  • Replace 'four bytes' with '32 bits'.

I would argue that describing the size with bytes is valuable from the perspective of people who are new to rust. I do see your point though, and I propose adding in an additional note about how this is 32 bits and potentially even renaming "bytes" here to "octets", as the byte has historically been used for storage units of a variety of sizes.

If the knowledge about byte sizes is indeed valuable to Rust newbies, the integer data types should have been described with their byte sizes as well. Instead, their names and description is focused on the mathematical value space (numbers from 0 to 4294967295, represented by 32 bits) and not on the storage technology and the storage units. Mixing these concepts takes more mental capacity from the reader than necessary.

I'm against "adding 32 bits" as that would leave the distracting "four bytes" in the text. The words "four bytes" shouldn't be there.

The book should only talk about bytes when it comes to serialization and deserialization, which may appear in a later chapter or not at all, I haven't read so far yet.