Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thoughts about Option.get #25

Open
mgyucht opened this issue Jan 20, 2016 · 3 comments
Open

Thoughts about Option.get #25

mgyucht opened this issue Jan 20, 2016 · 3 comments

Comments

@mgyucht
Copy link

mgyucht commented Jan 20, 2016

I think we should not use Option.get in our code. When the object in question is None, the error message is a cryptic NoSuchElementException: None.get. Instead, we should use Option.getOrElse(throw new Exception(exceptionMsg)) so that it is easier to discover where and why the object was None in the first place.

@rxin
Copy link
Contributor

rxin commented Jan 20, 2016

I tend to agree - the only exception might be when the scope is super local and known for sure there is an element (e.g. with an if check beforehand on option.isDefined)

@mgyucht
Copy link
Author

mgyucht commented Jan 20, 2016

Yeah, that makes sense. At least it reduces a level of nesting. Also if the variable is volatile you might run into race conditions between the check and the dereference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@rxin @mgyucht and others