YouTube link: https://www.youtube.com/watch?v=kCcWxI85hbg
Our guests Andrew Phillips and Nermin Šerifović (aka @higherkinded) bring us puzzlement both enlightening and confounding. They are the authors of Scala Puzzlers (Artima Press), creators of scalapuzzlers.com, and keepers of @ScalaPuzzlers.
In this episode the hosts try to stump the authors, the authors try to stump the hosts, and everyone goes home confused.
your hosts this episode: Seth Tisue, Josh Suereth
Two actual puzzlers are discussed in the podcast. If you're listening on audio, it will help to look at the code. For the first puzzler, the code is shown below. For the second, see http://scalapuzzlers.com/#pzzlr-056.
- Josh is stealing paintings from his hotel room
- Nermin started Boston Scala Enthuasiasts. Andrew is best known
for owning a large portfolio of Scala-related domain names.
- contact Andrew's sales staff for pricing information
- inspired by Java Puzzlers, a book by Joshua Bloch and Neal Gafter
- scalapuzzlers.com came first; most puzzlers are submitted by the user community
- were they worried this would throw fuel on the Scala-complexity fire?
- some puzzlers can be fixed, others are inherent?
- this puzzler's so new it isn't on the site yet. it's from a recent Scala mailing list thread
- here's the code:
val nats: Stream[Int] =
1 #:: (nats map { _ + 1 })
val odds: Stream[Int] =
1 #:: (odds map { _ + 1 } filter { _ % 2 != 0 })
nats filter { _ % 2 != 0 } take 2 foreach println
odds take 2 foreach println
- if it's not a language-quirks puzzler, is it still a puzzler?
- shouldn't that
val
be alazy val
? or does it matter? - Seth confidently makes a totally wrong assertion about
#::
, and even says "definitely" while doing so - Josh and Andrew agree on a fix that (we realize later, after the show has ended) doesn't actually help
- puzzler #56 from the site: "An Exceptional Future"
- this one's about
Future
about how it handles different kinds of Throwables - some of this is standard Java/JVM stuff, but there's a Scala-specific part too
- earthquake!
- Martin Odersky stumped on a plane; Adriaan Moors and Daniel Spiewak stumped live
- a key survival skill in Scala is to remove portions of your own brain with a laser
- a handful of puzzlers in the book are already fixed in newer Scalas,
or at least give warnings with certain compiler flags
- Wartremover can help too. (and Scalastyle, Abide...?)
- Josh's parting advice before the hotel police drag him off: to avoid puzzlers, learn how not to use implicits
- on
implicit val
vs.implicit def
, and on implicit values which are themselves functionsimplicit val s = Set(1, 2, 3); 2: Boolean
, anybody?
- and don't forget that implicits have names, and the name doesn't matter... except when it does
- illegal popcorn is served, exhausted conferencegoers soothed
- Predef: disable parts? heck, disable it all
- Punchcard Puzzlers was a big seller back in 1965
- Andrew puts Seth on the spot
- hope, yes. but not too much, and not too soon
- Andrew asks the big question: how we can make Scala safer for more people?
- Seth: we need more static checking. we have some checkers, we need more and better. Abide is a promising new entrant, and needs community participation.
- Nermin: compiler flags help. style guides help. there's a Spark style guide in which they recommend avoiding a lot of language features.
- the "five second rule": don't eat your code if it's been on the floor for more than five seconds
- Andrew: in the static-checking space, don't forget SuperSafe
- Seth: the rise of Spark changes the makeup of the Scala community. it ups the ante for needing to make the language easier and safer.
- Andrew: and it means fewer people are coming straight from Java
- "Patrick" in the audience wants to know if there's a coupon
code for the book
- Bill Venners from Artima helpfully provides: "Here's a 35% discount code for Scala Puzzlers that will be good through midnight Central Time, Friday, September 4. PUZZLEWAGS"