Re:Show HN: How to program in Rust as if it was old school C...
by scotty79 on Tuesday December 20, 2022 @03:57PM
(#34072432)
For that small price you get security against everything except memory leaks (which you don't get anyways in this bare C++ either) not to mention other Rust niceties while keeping superficially same convenient semantics.
Re:Show HN: How to program in Rust as if it was old school C...
by stoddardlabs on Tuesday December 20, 2022 @07:39PM
(#34075131)
You know, you don’t NEED to qualify every slightly negative comment about Rust (especially when the comment is made in jest)
Re:Show HN: How to program in Rust as if it was old school C...
by scotty79 on Wednesday December 21, 2022 @05:33AM
(#34078925)
I am afraid that I'm just like that. When people jest with me in the real life I often choose to respond as if it was said seriously. I mean, I don't get upset or anything. Just refuse to recognize something as a jest and respond charitably but seriously as if someone was only half-joking. Not sure why I do that. I think I feel that's the best I can do for someone who attempted humor in a way that fell flat on me.
I'm not talking about GP right now. "Thanks, I hate it." actually made me smirk a little bit and his links to assembly were actually super informative. So in this case humor was great but there was also substance which I felt I need to respond to with "what's in it for me".
Re:Show HN: How to program in Rust as if it was old school C...
by worldsavior on Tuesday December 20, 2022 @04:12PM
(#34072654)
It's because of the libraries. They get compiled once.
Re:Show HN: How to program in Rust as if it was old school C...
by steveklabnik on Tuesday December 20, 2022 @04:39PM
(#34072995)
It’s because they don’t have the same semantics, you are adding overhead with the Rust version in multiple ways.
Re:Show HN: How to program in Rust as if it was old school C...
by scotty79 on Tuesday December 20, 2022 @05:02PM
(#34073331)
I wonder how much difference there would be if I used shared_ptr in C++ instead of the bare one.
EDIT:
As far as I can tell less than 190 lines of asm but I don't know shared_ptr enough to produce exactly the same code.
Re:Show HN: How to program in Rust as if it was old school C...
by steveklabnik on Tuesday December 20, 2022 @05:45PM
(#34073869)
Yeah, that gets closer for sure. refcell is still going to add a bit of state to the value inside of the allocation, but at least the shared_ptr and Rc/Arc bits are the same semantic, so it'll be closer!
Re:Show HN: How to program in Rust as if it was old school C...
by worldsavior on Tuesday December 20, 2022 @06:09PM
(#34074146)
Look at the asm code of rust. You would see that most of the code there is the libraries (and yeah, also because of the semantics, which are powerful).
Re:Show HN: How to program in Rust as if it was old school C...
by steveklabnik on Tuesday December 20, 2022 @09:04PM
(#34075824)
... the library that implements those different semantics. If you wrote your own Rc and RefCell, that code would still exist, in your crate. Where it lives isn't the root cause.
Re:Show HN: How to program in Rust as if it was old school C...
by doodlesdev on Wednesday December 21, 2022 @12:42AM
(#34077100)
If you enable optimizations it gets reduced to 200 lines. C++ -O1 reduces it to 30 lines of ASM. Both are awful, just do normal Rust or use something else entirely.
I also believe they would be much closer if the C++ example used shared pointer.
https://godbolt.org/z/YYaK8f9rz
Rust compiles down (up?) to 1428!
https://godbolt.org/z/91YfzT5fb
Thanks, I hate it! Do dynamic typing next!