Scorex
Scorex copied to clipboard
Improve the use of Option and Try
As discussed in #242 it would be good to follow the following approach to improve the way we use Option and Try types and reduce/remove the use of unsafe methods as .get if possible.
Approach
- If we expect a method parameter not to be optional, then we should try not to use an Option/Try as parameter type. This would lead to the client to handle the lack of necessary information before calling the method.
- If a method should receive this kind of optional values and depends on them to be successful (Some/Success) and can't provide a value of type A to handle failure cases, then one should return to the client an Option[A]/Try[A] instead of A. It should then be the client the one to either again solve the issue or forward the returned Option/Try.
Other approaches are welcome to this discussion.