4 ms·
I'm very sad to see that reflection (or introspection) won't be making an appearance in c++17. Even limited introspection suggested in N3951 (http://woboq.com/b
by green7ea 11y ago
I'm very sad to see that reflection (or introspection) won't be making an appearance in c++17. Even limited introspection suggested in N3951 (http://woboq.com/blog/reflection-in-cpp-and-qt-moc.html http://woboq.com/blog/reflection-in-cpp-and-qt-moc.html) would be a great boon. Implementing features that would render Qt's preprocessor useless would be a great start and would standardize the tooling around c++ as well as reducing the amount of boilerplate code required to do something as simple as serialization.
- Animats 11y agoLack of serialization/marshalling support at the language level is a big issue. Serialization eats up a lot of CPU time in any message passing system, it's slow when done with run-time introspection, and it's something that can be done fast by code compiled for a specific structure. Attempts to speed up serialization usually involve preprocessors; there are preprocessor code generators for Google protocol buffers and OpenRPC marshalling. It's probably possible to do serialization code generation at compile time in Rust.
- stevedonovan 11y agoOr any language where you can write code that generates code at compile time, like Nim. Unfortunately, any answer for C++ is unlikely to be so elegant, so preprocessing feels like a lesser evil.
- Animats 11y agoIf you had some way to apply templates to each element of a structure in sequence, you could use template metaprogramming to do marshalling. Suppose you could write struct pnt { float x; float y; bool valid; }; pnt p; and then have auto s = serialize(p); expand into auto s = serialize_field("x", p.x, serialize_field("y", p.y, serialize_field("valid", p.valid))) then serialization could be implemented by defining serialize_field for each type.
- kibwen 11y ago> It's probably possible to do serialization code > generation at compile time in Rust. This is precisely how it's generally done. See https://crates.io/crates/serde https://crates.io/crates/serde for an example.
- atilaneves 11y agoOr any other language with compile-time reflection, such as D. Here's my serialization library in it: https://github.com/atilaneves/cerealed https://github.com/atilaneves/cerealed
- seivan 11y agoI am using https://google.github.io/flatbuffers/ https://google.github.io/flatbuffers/ right now, it's going slowly but I'm still learning c++
- raverbashing 11y agoWell, to be honest C++ is trying too little, too late And to be fair, the competition is still getting there where it really matters that you write C++ code. Go is starting to be supported on ARM, but given that it had issues with i386 I'm not sure what kind of issues might show up. Swift is for now Apple only, not sure about Rust
- pjmlp 11y agoGo and Rust still need to find their way into OS vendors SDKs. Many of us only use first class support languages, regardless of other options might exist out there.
- raverbashing 11y ago> Many of us only use first class support languages, regardless of other options might exist out there. Yes, that's the reality unfortunately There are very few options for small embedded hardware. Or even for desktop applications, as forgotten as they are today (though Java plays in this field)