Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethTisue/295e58355cda3f9dadfc to your computer and use it in GitHub Desktop.
Save SethTisue/295e58355cda3f9dadfc to your computer and use it in GitHub Desktop.
Scalawags #32: Scala Puzzlers

Scalawags #32: Scala Puzzlers

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.

Intro (0:00)

  • Josh is stealing paintings from his hotel room

How'd this start? (0:30)

  • 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?

A Stream puzzler (13:35)

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 a lazy 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

A Future puzzler (24:30)

  • 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...?)

Implicits (36:50)

  • 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 functions
    • implicit 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

Puzzlers live! (42:10)

  • illegal popcorn is served, exhausted conferencegoers soothed
  • Predef: disable parts? heck, disable it all
  • Punchcard Puzzlers was a big seller back in 1965

Will Dotty save us? (47:55)

  • Andrew puts Seth on the spot
  • hope, yes. but not too much, and not too soon

Safer Scala (50:50)

  • 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

Conclusion (1:01:15)

  • "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"

Andrew
Nermin
Josh
Seth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment