News for hackers. Stuff that matters.
Re:Rust is more than safety by sidlls on Wednesday December 28, 2016 @02:46PM (#13273093)
I have almost the exact inverse view: when I write C++ code, I shed a tear if I can't disable exceptions and use something very analogous to Rust's Result type. I can't tell you how many times I've written some version of 'class Result<T> { union {int, T} }' (obviously, that's illustrative, given all the extra work that has to go into writing a proper tagged-union in C++) for use with C++ code at jobs I've had in the past. Rust's implementation here is great, in my opinion.
Re:Rust is more than safety by softc on Wednesday December 28, 2016 @02:59PM (#13273166)
Just to clarify, In this specific case, I think we're talking about interface, not implementation.

Your preference is fair, since interface is a subjective issue. Personally, I find it more convenient to simply assume all code can encounter a error. Given that assumption, I find it redundant to add extra syntax to fail on unhandled errors.

Re:Rust is more than safety by lacampbell on Wednesday December 28, 2016 @03:22PM (#13273312)
As an aside: I'm curious as to why you'd implement a Result type in C++ as a tagged union where you have to manually branch on the tag, and not as an abstract class with two children.
Re:Rust is more than safety by dbaupp on Wednesday December 28, 2016 @03:47PM (#13273485)
The union avoids requiring an allocation for, say, returning a Result.
Re:Rust is more than safety by lacampbell on Wednesday December 28, 2016 @04:02PM (#13273623)
I am not sure what using an object vs using a struct with an enum + a union has to do with allocation. My C++ is rusty (no pun intended).
Re:Rust is more than safety by dbaupp on Wednesday December 28, 2016 @05:56PM (#13274390)
The equivalent of a function returning Result<T, E> in Rust would be returning something like unique_ptr<ResultBaseClass<T,E>> because the two subclasses have different sizes and thus can't be returned directly (or else one will be object slicing). The struct version stores everything inline from the start (it has a single static size) and so can be returned without needing a pointer.
Re:Rust is more than safety by lacampbell on Wednesday December 28, 2016 @07:38PM (#13274895)
My C++ skills have atrophied worse than i thought - I completely forgot you can't return an abstract class by value.
Re:Rust is more than safety by sidlls on Wednesday December 28, 2016 @03:24PM (#13273321)
I find it easier to reason about.
Re:Rust is more than safety by lacampbell on Wednesday December 28, 2016 @03:42PM (#13273440)
Interesting. I tend to view ADT as syntax sugar for a shallow class hierarchy of small immutable objects with no encapsulation or behaviour.