I have been doing some Scala lately, have to say I...
# random
c
I have been doing some Scala lately, have to say I prefer Option.. did not think I would…
o
why? because of the methods you can apply to it?
c
a variety of reasons, it really does accomplish what you want: fewer NPEs, and it does not have an override button that will let you still get bitten in the ass if a fool chooses to use it…
r
I prefer Option also, but the killer “monad” in my opinion is Either. It provides a way to handle errors that I find more elegant than exception handling.
c
Yeah. The amount of overlap between Scala, Kotlin and Swift is astounding. Have you looked at ‘The Red Book’? Has a section on errors without exceptions.
r
Yeah, that books is pretty good. I’ve used that approach to error handling in Kotlin also. I used to just create lots of sealed classes, but overtime I just use Kategory’s Either and Try. There is a lot there that I still need to learn about proper idioms when dealing with errors and exceptions. It does seem better than throwing and handling exceptions everywhere.
c
Exceptions, like so many things in Java, were born broken and never fixed..
k
Isn't the "button" with Optional just unwrapping it and using it still? 🙂 It's effectively a longer version of writing !!
c
What button? the typical sequence with Optional in Scala is you get your result and then pattern match it for some or none
k
skip the variable.isDefined and do variable.get is the same as Kotlin's !! if you want to do the pattern match thing, it's similar to doing "something?.blah ?: else" I think.
r
getOrElse is more like the Kotlin way you suggested. With pattern matching the compiler will make sure you cover all the cases. The added benefit tho, is not Optiona, but Either (I think), where the presence of an error is helpful and you don’t have to be branching everywhere, until you reach the end of the pipeline.
c
Yeah I guess that is true, @kenkyee but, that’s just using the classes wrong right?
k
Exactly... That's why I said Scala had the same button 😀
c
But dude, that is MY argument! I am saying since the failsafe appearance of compile time enforcement is easily short circuited, there is no significant improvement: both solutions rely on good behavior.. (at least neither is as dumb as Java’s Optional…)