Skip to content

suggestions on 2nd edition #773

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

Closed
robnye opened this issue Jun 16, 2017 · 5 comments
Closed

suggestions on 2nd edition #773

robnye opened this issue Jun 16, 2017 · 5 comments

Comments

@robnye
Copy link

robnye commented Jun 16, 2017

The 2nd edition is really much clear than 1st one. I love it.

Here are my suggestions,

  • As a C/C++ developer, I'd like to see how "enum" works in detail, especially memory layout. Several years ago, I began to study Haskell, the enum shocked me. From C/C++ viewpoint, enumeration is simple definition of integer and struct/class is flat memory block (virtual table doesn't change it), while enum in Haskell/Rust would surprise new comer if no memory model is presented. Actually enum is somewhat similar with "struct inside union", from which point it looks like it is easier to understand (the comparison is just for understanding)
  • It will be more practicable if some examples on the substitute ways from C++ inheritance, polymorphism to Rust implementation.

Since it is not an issue, please feel free to close it if accept or not.

Thanks,
R.N

@burdges
Copy link

burdges commented Jun 17, 2017

Do you mean roughly speaking? I'd assume it's roughly that the index goes wherever it avoids disrupting alignment, no? As for the actual rules, I think enum layout is slowly evolving in rust-lang/rfcs#1230 along with maybe NonZero. Also, there are fancy optimizations blocked on numerically constrained types, which look blocked on type level numerics. I'd expect the actual ABI will continue evolving for several years to come.

@robnye
Copy link
Author

robnye commented Jun 17, 2017

Yes, it is roughly speaking. Actually I am not talking about Rust lang, instead I just want to share my proposals to the Rust book. IMHO, many pure C/C++ programmers are very familiar with C memory model, C++ OO, C++ template, STL and boost etc, and some other languages e.g. Python/Java, while they don't have chance to take a look on languages like Haskell, OCaml etc only because they don't need it in work. Especially some of them are system level developers, who cares about cache missing, bytes alignment, MP/MT programming etc. Now Rust is suppose being a better substitution of C/C++, maybe the book could assume some of readers are them to smooth the learn curve for them.

@steveklabnik
Copy link
Member

Thanks for these comments!

I'd like to see how "enum" works in detail, especially memory layout.

So, technically speaking, enum layout in Rust is unspecified, so we can't actually say. As @burdges points out, even the current implementation has a bunch of complexities, but we don't get into that level of detail in the book, as none of that is stuff you can rely on.

It will be more practicable if some examples on the substitute ways from C++ inheritance, polymorphism to Rust implementation.

We tried to cover this in the OO chapter, maybe we didn't do a great job.

@robnye
Copy link
Author

robnye commented Jun 17, 2017

Thanks, now I understand what you said regarding "enum" stuffs.

Wish more developers turn to Rust.

@carols10cents
Copy link
Member

I'm going to close this-- please take a look at chapter 17 for some examples about what to use instead of inheritance and reopen this if you have any ideas for improvement! https://doc.rust-lang.org/nightly/book/second-edition/ch17-00-oop.html

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

No branches or pull requests

4 participants