A new book on Rust I am writing

Hi All :wave:

I am learning Rust and the best way is to document what you are learning.

In that spirit, I am maintaining a book on Rust language. It covers some fundamentals that I learned so far as well as bunch of design patterns I have explained with easy to follow sample applications.

I plan to expand the project with common algorithms next.

I appreciate any help, guidance and collaboration.

The Project's Github link (please :star::star::star: if you like it :face_with_peeking_eye:)

The Book's Site:
https://idiomatic-rust-snippets.org/

2 Likes

Interesting, I will bookmark it and have a look soon.

As you might know, I have one as well: Rust for C-Programmers

I saw that you dared to use an URL with the string "rust" in it. I considered that as well, but my fear was that that might look too "official" and would result in legal trouble with the Rust Foundation. Have you consulted your lawyer about this? I would like to use an URL containing the word rust as well, to make my book a bit more popular and easier to find. But well, the Rust Foundation might have dozens of layers. Actually I have seen no other domain name with rust in it yet. Advertising online Rust books is a bit difficult, I have the feeling that the only way to really promote a Rust book is publishing at Amazon, or a big publishing house, unfortunately.

1 Like

If you have any worries related to trademarks, please reach out to the foundation. They'd be happy to help make sure things are hunky-dory.

We want people to write books about Rust! It's just that there are certain legal requirements we have to make sure to uphold in order to keep the trademark.

4 Likes

Hi Stefan, honestly I didn't think about it while using "rust" in the domain and if it would cause a trouble with trademarks. I have no intention to convert this to a commercial business. But it this becomes a concern I would probably just update the domain name. Hoping they won't get after me for this though. I will make sure to add a note in the first page that this is a personal project and not associated with Rust Foundation in any way.

2 Likes

Not sure how to phrase this, but... how much generative AI went into writing this book?

Not sure if this question is directed to me or saltukalakus?

For my book, each chapter has in multiple passes been grammatically corrected by various AI tools. As you might suppose, I am not a native English speaker, so it is really difficult for me to produce perfect English texts. My last book, created in 2020, a introduction into the Nim language, got some negative critics due to grammar issues (and verbosity). That time I decided to never create an English book again. But now with AI it has become again some fun to create very good English texts. Well not always -- sometime AI tools just delete half of my texts. This can be frustrating, but I think I have to accept that sometimes my writing is too verbose :slight_smile: AI processed texts are a difficult topic. Some just hate and fear AI, some might think that we can say "AI, please create a book about ..." and we get a useful book. But that does not work. Even creating a initial draft for a chapter by AI typical fails. But rewriting a text section often works quite well, and AI can even remove repetitions and redundancies, which can be really helpful. But it can happen, that we have a chapter with 30 kB, and after we ask for a rewrite, we have less that 20 kB. I then do typically a diff, and add again what I find important. Conclusion: With AI even non native speakers can now create high quality texts, fast to read and easy to understand. While the official Rust book is not bad (I would give it 3.5 stars from 5) I would give "Rust for C-Programmers" already 4 stars, even when there is still some stuff missing, and the text should get some more revisions. All that has been created in only about 400 hours -- I assume 300 hours hours would be needed to finish it, if I leave out macros and async. (I know nearly nothing about Rust's macros and async, and have no motivation to learn that currently.)

A totally different story are AI fake books. I heard that there are some at Amazon, but it is difficult to verify. I have noticed that in the last 18 months the number of published books have significantly increased. For example, for Nim we had for a decade only one book, created in 2017 by Mr. Picheta. Then in 2020 I created my one, and finally Mr. Rumpf created his in 2022. But then suddenly a dozen more appeared, I have listed all of them at Books | Nim Programming

That is a bit strange. On the other hand, maybe now people from Asia, Africa, and other parts of the world have the possibility to publish their books in English for the first time? Perhaps we should try to create a lists of reviesed Rust books? Because I find it a bit sad if at Amazon there are dozen of excellent Rusts books which no one dares to buy, because it could be AI trash.

It was directed at saltukalakus, my bad!

As a non native speaker myself, I definitely wouldn't judge any other non-native speaker for their grammar, or for using an AI tool to check it.

Oh sorry, so I spent so much effort for the explanation. I think AI is just right, my writing is sometime too verbose :slight_smile:

My worry about AI generated content is that we are going to get flooded with books, articles, etc like this: C 4 Decimal Places: C Explained - Bito. That example is a long and extensive blog post on how to use the %.4f format specifier in C. Including lengthy sections on the benefits of using it, pitfalls of using it, debugging it etc. Notice that it is about %.4f not %.5f or any other number of decimal places, not about any other format specifier or printf() in general. No, it's a whole tract on exactly %.4f and nothing else.

I did not know whether to laugh or cry on finding that. If that keeps up there will be so much junk on the net we will never be able to find anything useful.

Anyway, never mind, I really came here to remind that when writing a book one should always have an audience in mind. A book on Rust that might be immediately attractive and useful to old school C and C++ users may be very different from a book targeted at Python or JS users. And different again for those with little or no experience in software.

5 Likes

I am heavily using AI while building this. I will add a note in the readme somewhere on it. I expect over time the percentage of AI dependency will reduce as I delve into more subtle topics.

1 Like

Yes, that worry is very justified. However I am watching the world since a few decades now. We are flooded with junk and garbage as least as long as the Internet became available to the ordinary people outside of universities. YouTube, Twitter, X, Facebook, Udemy, Medium -- all mostly collections of garbage. I assume most of Reddit or Shlasdot and such as well. Forums and mailing list are typically populated by people who make a typo in every third word, ignoring capital letters. I think back in the early 90's when we had only the UseNet it was a bit better. Note that most scientific papers are now bullshit as well. The number of published papers has drastically increased, but the quality and relevance of the content is now very bad. No one reads that any longer. If required, they copy it into an LLM and ask for a summary.

Actually I have no real idea if, why and how people manage to use AI tools to generate garbage. For most of my tests AI content is excellent. I sometimes compare a response an AI gives me with Wikipedia articles -- in most cases the AI content is shorter, more precise, easier to read and to understand. One reason might be the way I ask. I think one has to ask very precisely, not in the way some people ask questions in web forums: "What is the best programming language", "How can I best learn Rust", "Which stocks should I buy". Another reason might be, that I am a paid user of OpenAI. Some people have said that paid users get better quality, e.g. it was said that Claude responses become worse for free users when the server load is high. And finally, OpenAI seems to store user profiles. When I typical ask for precise content in in good, correct technical English, they might store that internally. For Llama 3.1 I have actually observed that the answers were a bit verbose, so I stopped using it. I think Claude's (sonet) answers have been fine most of the time. Next I was going to test DeepSeek 3 from China, I think I will try that in the next days, and see it I will be able to persuade it to generate bullshit :slight_smile:

Thanks for your effort to contribute in the popularity of Rust.

My "TLDR version" of this (which I shamelessly stole from someone I can't remember): AI is great when it's giving you decisions, it's terrible when it's making decisions.

It's generally pretty good at condensing, or detecting non-idiomatic English usage, so I don't think you should be concerned about your use of it, just keep in mind it tends to remove "flavor" by default: in longer texts especially having consistent quirks in your language is a positive up to a point.

1 Like

I like Angela Collier ´s take on AI:

"AI does not exist but it will ruin everything anyway":

1 Like

Eh, a lot of that is just her ignoring the "AI Effect", roughly that we've always called the thing we're researching "AI" until we made it and it didn't "look hard enough" to be called "intelligent": path finding, computer vision, text to speech etc. (perhaps just this is the first time someone made something they didn't understand at all!)

I'm actually happy we're mostly past the nonsense argument of if something "counts" as AI, though we've got the only slightly better argument of if it "actually understands" something instead. (Specifically, this is a nonsense question without having a particular meaning of "actually understanding" something, for example a common definition is "can generalize information about a specific situation to apply it in a different situation" - something LLMs are often fairly decent at, though there's other definitions that LLMs are much worse at.)

1 Like

When you posted your message a week ago, I had a random look at Merge Sort - Idiomatic Rust Snippets

The text said "This implementation ensures that the array is sorted in-place". I learned merge sort a few decades ago, and was not able to instantly remember details, but my feeling was that merge sort always needs a buffer, at least half as the size of the initial data. For your Rust implementation, it might indeed appear that the sort occurs in place as in quick sort. But actually the merge_sort() call is recursive, and each time there is a let mut ret = arr.to_vec(); call involved, which heap allocates a new vector. So the total heap allocated size is twice the initial data size. So at least the initial statement is misleading. I can currently not remember details, but I think merge sort implementations exists, that reuses a heap allocated buffer that is only half as large as the initial data. And non-recursive implementations exists as well. Further, you should mention that merge sort is a stable sort, and has advantages in worst case scenarios, where recursive, unstable quick-sort can have bad performance and can lead to stack overflow.

I think without this information (and much more might be missing) your pages are not that helpful. We have already pages like Rosetta Code that just show some code, and had their merits some decades ago.

And maybe you can explain to me as a non native English speaker what you and other intend with the term idiomatic? It is sometime used in conjunction with programming language, but makes no sense for me. It seems to imply "we write the code just this way, we do it because we do it, there is no real reason for it". This is a bit strange, so I always avoided using the term "idiomatic".

To be frank, you probably should not waste your time looking into obviously unaudited AI generated content.

1 Like

Hi Stefan and @zirconium-n , the algorithms section hasn't been completed.( I put a WIP note in the entry page as there are some errors including some samples don't run and there may be some other issues too) Essentials and Patterns sections have been audited by myself. Still I don't guaranty there is no mistake there too as I am a Rust learner and may miss things.

If you notice any mistake please feel free to send a PR or open an issue and I will be happy to merge or work on the issue when I am available.

1 Like