3 ms·
> I want to live in a world where the function looks like this (...) Here the question mark tells us that if the function returns an error, we should return tha
by lmilcin 5y ago
> I want to live in a world where the function looks like this (...) Here the question mark tells us that if the function returns an error, we should return that error (...)
Ever heard of exceptions?
This is exactly what exceptions are made for. To allow you to write simple code but still make sure errors are propagated through your code.
It also makes it easier to write code that has to run something regardless of an error (using try/finally), while still ensuring that error is passed through your function reliably.
The question mark isn't necessary at all. Why would you pollute your code with additional character? It just says "I want to have a broken application that does not react to an error if I forget to put in a question mark"
- ghoward 5y agoNot GP. I think a great article detailing why exceptions are not desirable is http://www.lighterra.com/papers/exceptionsharmful/ http://www.lighterra.com/papers/exceptionsharmful/ . > The question mark isn't necessary at all. Why would you pollute your code with additional character? It just says "I want to have a broken application that does not react to an error if I forget to put in a question mark" I'm no Rust expert, but I think the compiler will error if you don't put the question mark?