Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.1 Understanding Ownership, Memory and Allocation: unfortunately #3823

Open
rillig opened this issue Jan 21, 2024 · 5 comments
Open

4.1 Understanding Ownership, Memory and Allocation: unfortunately #3823

rillig opened this issue Jan 21, 2024 · 5 comments

Comments

@rillig
Copy link

rillig commented Jan 21, 2024

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • unfortunately
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • src/ch04-01-what-is-ownership.md

Description of the problem:
The text says:

Unfortunately, we can’t put a blob of memory into the binary for each piece of text whose size is unknown at compile time

  • The word Unfortunately describes a situation that is not desirable to change.
  • It wouldn't be a fortune if a blob of memory were allocated in the binary for each piece of text.

Suggested fix:

  • Replace Unfortunately, we can with We can.
@StefanSalewski
Copy link

Thanks for reporting. That section was indeed awkward to read. This is what GPT-4 suggests:

In Rust, string literals are known at compile time, enabling their direct incorporation into the final executable. This integration contributes to the speed and efficiency of string literals. However, these benefits are intrinsically linked to the immutability of string literals. It's impractical to embed a memory segment into the binary for each text string whose size is not predetermined at compile time and may vary during program execution.

@rillig
Copy link
Author

rillig commented Jan 28, 2024

I don't trust GPT-4 to be good enough for the job, as beginners should not face wild hallucinations in an introductory text, even if they sound correct at first glance. The GPT-4 text has several complicated words that don't contribute to the understanding. The GPT-4 paragraph looks like it were a rephrased variant of the current section from the book.

Here's how I would rewrite the section from the book:

Since strings literal are immutable and known at compile time, their text is embedded in the final executable. This way, their lifetime is "forever", thus there is no need to track ownership of string literals. For a String, on the other hand, the length and text can change while the program is running, therefore its text cannot be embedded in the final executable.

@StefanSalewski
Copy link

StefanSalewski commented Jan 28, 2024

For me, as a non native speaker, GPT-4 is a great help, its wording is typically much better than mine. Of course it is not always 100% correct, so we have to do carefully proof-reading. You are correct, the cited GPT-text is a rewording of the book, but I like it: https://chat.openai.com/share/7d67c747-7d1d-4e93-b012-1d59188eacd3
For me, your text appears grammatically wrong: Should "strings literal" be "string literals"? And your text section is not that great to read, sorry. This is how GPT-4 would reword it: https://chat.openai.com/share/8a02da98-5fab-451a-9792-8bb1f252ddff

[EDIT] Sorry, first pasted link was wrong.

@rillig
Copy link
Author

rillig commented Jan 28, 2024

You're right, I made a typo and actually meant "string literals".

@chriskrycho
Copy link
Contributor

Thanks! I agree that this is a bit confusing, and at first blush your suggestion is a nice improvement. We'll chat and see if we want to run with that or iterate on it further!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants