I was invited to give this talk at the Wix Backend Guild Day, an internal event which was broadcast live internationally, on 2018-04-12
Video: https://youtu.be/cQ7UvUybceA
These days sbt is the de-facto build tool for Scala, but most of us just write the minimum viable build.sbt file, import the libraries we need (and maybe throw in some sbt-assembly) and forget about it.
In this Good Practices session, you will learn about making your build safer and more robust by making the Scala compiler work for you and through using some sbt plugins.
This talk will be quite high-level. There will be no need for prior knowledge of sbt and it should be beneficial for you even if you don’t use sbt.
7. “
”
THE COMPILER IS YOUR FRIEND
AND FRIENDS TELL FRIENDS
WHEN THEY TRY TO DO STUPID THINGS
Hila Noga, “From Prehistoric to a New Age”, Scalapeño 2016
https://www.youtube.com/watch?v=N9loHZAI1NM
11. “
”
-Xfatal-warnings
IS LIKE GLOBAL WARMING
YOU WANT TO DO SOMETHING ABOUT IT
BUT YOU NEVER DO
AND NOW IT'S TOO LATE
Andrew Phillips, “Essential vs Accidental Complexity in Scala & Dotty” (paraphrased),
ScalaWorld 2016
https://www.youtube.com/watch?v=Ay-9aanosUM
12. scalac Flags
-deprecation
-unchecked
case _: Option[Int] =>
-feature
What level of Scala are you on?
-language:implicitConversions (use splain)
13. scalac Flags
Advanced Settings: -X
-Xcheckinit ※
-Xfuture
-Xlint
Run scalac –X for a list
class Foo {
val bar = baz // not yet
val baz = 1
}
17. YMMV
Do what’s right for you
“Recommended Scalac Flags for 2.12” by Rob Norris (@tpolecat)
https://tpolecat.github.io/2017/04/25/scalac-flags.html
20. Linters
(that you should care about)
-Xlint:*
WartRemover
Scalafix
IntelliJ IDEA
Leif Wickland, “Toward A Safer Scala”, ScalaDays SF 2015
https://www.youtube.com/watch?v=CQY5ef6R_eg
21. WartRemover
All rules are opt-in
No “Better Java”
AsInstanceOf / IsInstanceOf
Null
Return
22. WartRemover
Good Practices
ExplicitImplicitTypes
PublicInference
implicit def foo(): Bar = new Bar()
def foo(): Bar = new Bar()
23. WartRemover
Language Best Practices
FinalCaseClass
LeakingSealed
final case class Foo()
sealed trait A
sealed trait B extends A
final class C extends A
24. WartRemover
Standard Library Best Practices
ArrayEquals
JavaConversions
Array(1.toByte) == Array(1.toByte)
javaList.asScala
27. “
”
ANY STYLE GUIDE WRITTEN IN ENGLISH
IS EITHER SO BRIEF THAT IT’S AMBIGUOUS,
OR SO LONG THAT NO ONE READS IT
Bob Nystrom, "Hardest Program I've Ever Written”
http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/
31. Versions
Metadata
Easy Consensus
Semantic Versioning
Breaking.BackCompat.Patch
Marketing.New.BugFix
Copy of Copy of Software Final (3).docx
32. Types of Versions
Canonical versions
1.2.3
Non-canonical versions
Between 1.2.3 and 1.2.4
Date? Branch? Hash?
Not even a version
Snapshots