News for hackers. Stuff that matters.
Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by steveklabnik on Wednesday March 31, 2021 @11:58AM (#26648871)
Rust does not have classes, strictly speaking, though you can define methods on structs.

https://crates.io/crates/cxx is the simplest way to do an integration. It is slightly more work than "just plop in" but it's not incredibly difficult. It's harder than mixing C and C++ together, but then again, almost no pairings of languages are that easy.

Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by bluGill on Wednesday March 31, 2021 @12:17PM (#26649143)
Then C++ doesn't have classes either, you can put methods on structs though.

Rust people keep saying there are not classes, but all a class needs it the ability to put methods on structs. Private access to some of the internals is often useful, but doesn't need to be enforced by the compiler.

Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by zozbot234 on Wednesday March 31, 2021 @12:28PM (#26649271)
The issue is not "structs" v. "classes" per se, it's things like inheritance, vtables and RTTI (also other C++ features like templates and exceptions), that need special ABI support in C++ for which there is no Rust-side equivalent. (meanwhile Rust traits are quite different from anything in C++, although they're used similarly)
Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by bluGill on Wednesday March 31, 2021 @01:40PM (#26650380)
None of those things are required for a class. I'll admit they are all useful at time, but all are abused.
Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by kupiakos on Wednesday March 31, 2021 @08:47PM (#26655349)
It largely depends on the definition of "class" you're using. You'll raise some eyebrows calling structs that can't support implementation inheritance "classes".

You can also have implement different associated functions based on properties of generic arguments, which is quite different in design from just attaching methods to a struct.

Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by steveklabnik on Wednesday March 31, 2021 @12:37PM (#26649413)
I mean, C++ has the "class" and "struct" keywords for a reason. (they are very similar, Rust structs are closer to "struct" than "class" though) There are a lot more things going on with C++ classes than syntax sugar for functions that have access to "this."

Also, while not in C++, in many languages, classes imply heap allocation, where structs do not.

Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by oriolid on Wednesday March 31, 2021 @12:51PM (#26649642)
What's the difference between struct and class in C++? IIRC the standard says they're the same except that members are public by default on struct and private by default on class. You could as well argue that C++ doesn't have structs.

The different allocation between structs and class objects in C# is a total head scratcher. Didn't it ever occur to the language designers that someone might want to choose how to allocate memory?

Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by steveklabnik on Wednesday March 31, 2021 @01:05PM (#26649869)
So, I dug into this a bit more, and you're right!

https://www.fluentcpp.com/2017/06/13/the-real-difference-bet...

Maybe it was the era that I learned C++ (which was in the 98 days), but I was taught something closer to this convention, and didn't realize until just now there was such little difference by the book. Just bundling some data together? Use a struct. Doing more? Use a class.

I still think this distinction is useful overall, because there often is more of one in many languages, but I will be more precise when speaking about C++ specifically in the future. I would also still argue the same thing overall, that is, Rust does not have what C++ calls classes. Our structs are apparently even simpler than C++ structs.

Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by logicchains on Thursday April 01, 2021 @01:45AM (#26657024)
Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by oriolid on Wednesday March 31, 2021 @01:43PM (#26650435)
It certainly makes sense to use struct and class to indicate what the type's role is. It's just good to keep in mind to avoid the confusion when you find the struct that has only pure virtual functions as members.
Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by est31 on Wednesday March 31, 2021 @03:04PM (#26651574)
C++ has to have structs because it wants to be (mostly) backwards compatible with C. I think that's the main reason they exist in C++.
Re:Android's new Bluetooth stack rewrite (Gabeldorsh) is wri... by pjmlp on Wednesday March 31, 2021 @04:56PM (#26653081)
That is correct.