tag:blogger.com,1999:blog-7206939994948735545.post7507994899564414295..comments2024-02-20T13:57:41.275+02:00Comments on Speaking my (programming) language?: Why Scala's Option won't save you from lack of experienceVassil Dichevhttp://www.blogger.com/profile/14522675986593535178noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-7206939994948735545.post-25244095553234167352010-10-30T07:45:40.005+03:002010-10-30T07:45:40.005+03:00Tony, thanks for reading my blog and thank you for...Tony, thanks for reading my blog and thank you for your informative posts, as well as your contributions to FunctionalJava and Scalaz- I learned a lot from them, and I hope others will.<br /><br />As for debunking Cedric- that was not my primary goal. I wanted to collect bits of information in something like a cookbook or reference for how Option can be used, with references to different useful blog posts. The audience is definitely not only Cedric, so if someone else finds this useful, this would be rewarding enough.<br /><br />Cedric has a point that this is one of the fundamental issues which folks have to come to grips with when they start learning Scala, so it's not a bad thing that there's a lot of awareness lately about the Option/Maybe types.Vassil Dichevhttps://www.blogger.com/profile/14522675986593535178noreply@blogger.comtag:blogger.com,1999:blog-7206939994948735545.post-42172716244754594342010-10-29T14:05:50.205+03:002010-10-29T14:05:50.205+03:00Hello Vassil,
The blog posts you mention regarding...Hello Vassil,<br />The blog posts you mention regarding Java are for demonstration only. The Option data type for Java is in wide use, mostly by people who are forced to use Java, by others who don't know any better.<br /><br />http://functionaljava.googlecode.com/svn/artifacts/3.0/javadoc/fj/data/Option.html<br /><br />Good luck debunking Cedric, but it can be a time-consuming (often with no reward) task.Tony Morrishttps://www.blogger.com/profile/17206456907461293947noreply@blogger.comtag:blogger.com,1999:blog-7206939994948735545.post-30069169324346855002010-10-25T18:26:07.445+03:002010-10-25T18:26:07.445+03:00Good point about the collection being optional rat...Good point about the collection being optional rather than the members. I think I struggle more with navigating collections of Option, which is probably why I fixated on that use case. Thanks for a great post.Adam Rabunghttps://www.blogger.com/profile/08575207879136726271noreply@blogger.comtag:blogger.com,1999:blog-7206939994948735545.post-76660328464202957962010-10-25T09:41:08.291+03:002010-10-25T09:41:08.291+03:00@Ittay:
Right, see Adam's followup: http://squ...@Ittay:<br />Right, see Adam's followup: http://squirrelsewer.blogspot.com/2010/10/scalas-option-will-save-you-from-most.html<br /><br />@Adam:<br />The employees collection is a List[Person]. The point of the example was to mirror to a certain degree Cedric's example, where the list variable itself could be null or an attempt to find an employee from this list could be null.<br /><br />I've read your article and it offers an interesting way of classifying NullPointerException, but note that a type system with no escape hatch like Haskell's will not allow unintended NPEs as they will be caught at compile-time.<br /><br />In this sense the employees variable is not intended to have nulls (or rather, None in this example).<br /><br />I would say that having a List[Option[Employee]] only makes sense if the employee position in the list matters, otherwise why not just make a list so that values would only be added if they're not None? Similar to the example "List(1, 2, 3) ++ Some(4) ++ None".<br /><br />A more likely operation where the value might be missing is getting a value out of a Map or finding a value in a list.<br /><br />I also think it's more common to have a List[Option[_]] as a result of mapping over some other list, where the function doesn't necessarily return a meaningful value.<br /><br />I hope that answers the question, but of course it depends on the use case.Vassil Dichevhttps://www.blogger.com/profile/14522675986593535178noreply@blogger.comtag:blogger.com,1999:blog-7206939994948735545.post-91576779821893842672010-10-22T19:33:44.700+03:002010-10-22T19:33:44.700+03:00Great article. One thing isn't making sense t...Great article. One thing isn't making sense to me, however. The 'employees' collection that is shown a couple of times is of type List[Employee], not List[Option[Employee]], right?<br />1. Doesn't that mean find/filter will NPE if your list contains nulls? And, isn't 'employees' having nulls the premise of the example?<br /><br />2. Wouldn't it be much more "idiomatic" to have List[Option[Employee]]?Adam Rabunghttps://www.blogger.com/profile/08575207879136726271noreply@blogger.comtag:blogger.com,1999:blog-7206939994948735545.post-49782137696740564632010-10-21T19:01:25.543+03:002010-10-21T19:01:25.543+03:00Note that Option is also good for when null is not...Note that Option is also good for when null is not an option ( ;-) ). For example, if your method returns one of the value classes (e.g., Int). In Java, you might try to return an unreasonable value, or box the value, both are uglyIttay Drorhttps://www.blogger.com/profile/06786072335349487451noreply@blogger.com