This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why have method "get" in Option?

51 replies
nilskp
Joined: 2009-01-30,
User offline. Last seen 1 year 27 weeks ago.
Re: Re: Why have method "get" in Option?
On Sun, Aug 22, 2010 at 3:22 PM, christopher marshall <oxbow_lakes@hotmail.com> wrote:
> > In the cases I use 'get' without checking I *want* a runtime error. It
> > means I made a wrong assumption in my code and it better fail fast.

> On 08/13/2010 05:06 PM, Nils Kilden-Pedersen wrote:
Um, wouldn't you prefer that the *compiler* might tell you that your code has a bug in it?

Oh sure, and how do you propose it should do that? (BTW, you don't know my use case)
 
> 100% agreed. I also use Option.get as a shortcut for: > {assert(!Option.isEmpty); Option.get}

I am managing to completely avoid using Option.get - I must be doing it wrong! 

Not wrong, just different use case.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland