4 ms·
> This leaves C++ being useful mostly for legacy codebases I'm pretty sure people said that about C++ when Java became popular. Rust seems like a fine languag
by einpoklum 5y ago
> This leaves C++ being useful mostly for legacy codebases
I'm pretty sure people said that about C++ when Java became popular.
Rust seems like a fine language, Zig sounds interesting, and Go and Swift I'm not familiar with. But I don't really buy your argument.
- xedrac 5y agoJava could never fill all of the spaces that C++ is used for because of the JVM and garbage collection. Rust certainly could, and should, in my opinion as a long time C++ developer.
- lelanthran 5y ago> Rust certainly could, and should, in my opinion as a long time C++ developer. I'm not a Rust dev, but I am curious how things like epoll would work in Rust. In C (or C++) I place a pointer to a structure in the epoll `event.data.ptr` field. When an event is returned by epoll_wait() all the caller has to do is run a function on that instance in `event.data.ptr`. It seems to me, that even with `unsafe`, you're not going to be able to do this in Rust unless all the code is unsafe. You cannot transfer ownership of the instance to `event.data.ptr`, can you mark the pointer or event structure itself as `unsafe`?
- zbentley 5y ago> you're not going to be able to do this in Rust unless all the code is unsafe. Why wouldn't std::mem::transmute (plus a little bit of hand-managed lifetime emulation) work here? It is unsafe, but doesn't require the unsafe modifier to be present on code beyond where the transmute happens. Unless by "all the code is unsafe" you mean related code is conceptually at risk of unsafety due to bugs caused by erroneous reinterpret-casts, then I think transmute should work here.
- adwn 5y agoI don't see why that would require making all code unsafe? You might want to take a look at mio's source code [1], which uses epoll on Linux [2], and which encapsulates epoll in a safe way. [1] https://github.com/tokio-rs/mio https://github.com/tokio-rs/mio [2] https://tokio-rs.github.io/mio/doc/mio/struct.Poll.html#implementation-notes https://tokio-rs.github.io/mio/doc/mio/struct.Poll.html#impl...
- lelanthran 5y agoAfter looking at the examples, it looks to me that it uses a hashmap (with a generated token to identify the connection structure). It gets around putting a ptr into the event structure (that epoll will then return) by putting a tokenID into it instead (that epoll returns), that the connection_handler function will then use to retrieve the connection instance that it needs to work with. IOW, in `C` I'd create an instance of a `struct connection_t` and `epoll_wait()` returns the pointer to the instance. This way, it appears that an ID is placed into the event structure and the { ID : corresponding instance } tuple is stored in a hashmap. `epoll_wait()` returns the ID, the caller uses that ID to get an instance to work with. Although, I could be wrong - I'm not a Rust dev.
- einpoklum 5y ago> Rust certainly could ... in my opinion as a long time C++ developer. Can you link to an explanation of, or an argument for, that claim?
- pjmlp 5y agoYep, and some projects failed hard on that regard, because the JIT infrastructure still wasn't good enough. I was part of one, whose goal was to replace a CORBA infrastructure based in HP-UX, with Websphere running on Solaris/Linux.