Scorex icon indicating copy to clipboard operation
Scorex copied to clipboard

Improve the use of Option and Try

Open EzequielPostan opened this issue 7 years ago • 0 comments

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

  1. 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.
  2. 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.

EzequielPostan avatar May 10 '18 01:05 EzequielPostan