6 ms·
Rust also shipped without reflection, which was available in the beginning. I was a bit disappointed as it was something I would have made use of for serializat
by saboot 11y ago
Rust also shipped without reflection, which was available in the beginning. I was a bit disappointed as it was something I would have made use of for serialization.
- FrozenCow 11y agoWouldn't it be better to create serialization functionality at compile-time? In the Java space some libraries are moving to compile-time code generation instead of relying on reflection. It is a huge win, since a lot more can be checked beforehand. Dagger 2 is a good example how it can be beneficial. It provides dependency injection at compile-time, which will in turn check whether all dependencies are satisfied. I haven't seen this being done at compile-time before, but it is definitely a step up from reflection-based DI. I'm not sure whether macros of Rust can provide such functionality, but the developers seem conservative when it comes to adding functionality. That seems like a good thing.
- saboot 11y agoI was referencing at compile time, yes. How does Dagger generate the code? Does it run an executable first? Yes, in C++ there is a similar library called ROOT which generates c++ files called "dictionaries" storing class information by running an executable over the files. I don't see (or understand) the downsides in providing the functionality for performing those steps at compile time though. The developers of ROOT are currently pushing for it to be included in C++17 (or beyond).
- mercurial 11y agoSometime I wish no runtime reflection was available to the programmer at runtime in Java, this would prevent people from being tempted to use brittle runtime magic. Of course, you would need a solid macro system instead. And thanks for the pointer to dagger, this looks like an interesting alternative.
- wyager 11y agoHow do you imagine that reflection would be useful for serialization in Rust?
- saboot 11y agoIn the way I asked here, http://stackoverflow.com/questions/29109967/why-dont-many-compiled-languages-include-compile-time-reflection http://stackoverflow.com/questions/29109967/why-dont-many-co... I am not very familiar with rust, is what I was describing currently possible?
- wyager 11y agoIt's not possible, but there's also no good reason to do it. You might as well just make an e.g. Serializable trait that requires you to manually implement the serialize function. You're not saving a whole lot of work by looping through the object's fields and saving them. Most objects only have a few fields to serialize anyway.
- pcwalton 11y agoSerialization is usually done better with macros, for performance reasons. We now have Erick Tryzelaar's fantastic serde library for high-quality serialization, competitive with rapidjson.
- saboot 11y agoOh, serde is interesting. I was specifically thinking about compile-time reflection but apparently rust's macros are more powerful than I realized. I'm inspired to look into this more, thanks!
- erickt 11y agoSerde (https://github.com/serde-rs/serde https://github.com/serde-rs/serde) is my baby, so let me know if you need any help with it. In a sense serde is a compile time reflection library. It's designed to recursively walk through a structure while calling a function on each component. While the primary purpose is to do serialization, it could be used to do other reflection-y things, like build a UI widget for arbitrary structures. To really support full reflection though serde would have to be modified to support in-place modification. It wouldn't trivial, but it's certainly not impossible.