3 ms·
Rust-Compare: a comparison of Rust, C++, and Java
- deleted 11y ago[deleted]
- Jweb_Guru 11y agoThere are some pretty wrong statements in here, such as that Rust won't allow you to iterate over an array of values.
- wspeirs 11y agoHow do you iterate over an array in Rust?
- Jweb_Guru 11y agofn main() { let x = ["a", "b", "c"]; for i in &x { println!("{}", i); } }
- wspeirs 11y agoThanks! Made the fix: https://github.com/wspeirs/rust-compare/commit/0c9fe97c7ae452baf523b3d8c5d4fbf20650eeee https://github.com/wspeirs/rust-compare/commit/0c9fe97c7ae45... You said there are "some pretty wrong statements," any others? You can also fork and fix if you'd like to help... it'd be greatly appreciated!
- xilec 11y agoIn section "Interfaces" impl Interfaces { fn my_method(a: isize) -> isize { return a; } } It isn't implementation of trait. It specify default implementation of trait. It must be: trait Interfaces { fn my_method(a: isize) -> isize; } struct Impl; impl Interfaces for Impl { fn my_method(a: isize) -> isize { return a; } } In section "Enums", you can apply default implementation of equality trait: #[derive(PartialEq, Eq)] enum BasicEnum { Option1 = 1, Option2 } and compare if e1 == BasicEnum::Option1 { e1 = BasicEnum::Option2 } In section "Parameters", you said "All three languages default to pass-by-value if not otherwise specified". For privitive types it's true, but it's not. Classes in Java have reference semantic (copy only address in method). Structs in Rust have move semantic witch is connacted with ownership concept (https://doc.rust-lang.org/stable/book/ownership.html https://doc.rust-lang.org/stable/book/ownership.html). In common, many basic things for Rust have very good descriptions in Rust Book (https://doc.rust-lang.org/stable/book/ https://doc.rust-lang.org/stable/book/). Please, pay attension on it and be more careful.
- wspeirs 11y agoI updated interfaces and enums. To your comment about move semantics for structs and such, I actually found the book lacking. I just did a quick Google search of the book for "move semantics" and couldn't find it anywhere. Where specifically does it talk about parameter passing?
- steveklabnik 11y agoMove semantics are here: http://doc.rust-lang.org/stable/book/ownership.html#move-semantics http://doc.rust-lang.org/stable/book/ownership.html#move-sem...
- eteran 11y agoGreat work! One thing I would change in the C++ Pointers & References is that things like: auto b = make_shared<char>('b'); is preferred over shared_ptr<char> ptr_b(new char('b')); This style is better because it's shorter and doesn't make you repeat the type :-) Unfortunately, make_unique didn't make it into C++11, but is there for C++14
- wspeirs 11y agoAdded a note... thanks!