Scala Compiler Tuning

Post image

As my Scala projects go on, I want to share some compiler configuration and tricks with you, which I use on many projects. Some tiny configuration options can greatly improve your code and warn you about things, you would probably never discover.

Basically, you can pass compiler options to scalac using console arguments:

$ scalac -deprecation -unchecked -Xlint something.scala

If you are using SBT, it’s even simpler… You can just use the following configurations snippet in your build.sbt file to add scala options:

scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xlint")

Common Scalac Options

There are some common options which I’d like to share with you. Most of them make it harder to compile “not that good” code or warn about certain conditions:

Option Description
-deprecation Emit warning and location for usages of deprecated APIs.
-feature Emit warning and location for usages of features that should be imported explicitly.
-unchecked Enable additional warnings where generated code depends on assumptions.
-Xfatal-warnings Fail the compilation if there are any warnings.
-Xlint Enable recommended additional warnings.
-Ywarn-adapted-arg Warn if an argument list is modified to match the receiver.
-Ywarn-dead-code Warn when dead code is identified.
-Ywarn-inaccessible Warn about inaccessible types in method signatures.
-Ywarn-nullary-override Warn when non-nullary overrides nullary, e.g. def foo() over def foo.
-Ywarn-numeric-widen Warn when numerics are widened.
-Ywarn-value-discard Warn when non-Unit expression results are unused.
-Ywarn-unused arn when local and private vals, vars, defs, and types are unused.

This is just a very small subset of available options for the Scala compiler. If you want to see all options available, just ask your scalac for it. To show all the options, just run scalac -X or scalac -Y. You can also just display the compiler help using scalac -help.

Finally, my personal Scala options (as SBT settings) for most of the Scala projects I currently work on:

// compiler tuning for the win - makes it harder to build schwurbl
scalacOptions ++= Seq(
  "-deprecation",
  "-feature",
  "-unchecked",
  "-Xfatal-warnings",
  "-Xlint",
  "-Ywarn-adapted-args",
  "-Ywarn-dead-code",
  "-Ywarn-inaccessible",
  "-Ywarn-nullary-override",
  "-Ywarn-numeric-widen",
  "-Ywarn-value-discard",
  "-Ywarn-unused",
)

Of course there are also such options for javac, the Java compiler. Just run javac -help or javac -X

As always, I really apreciate feedback of all kinds, or just send me your compiler configuration…

You May Also Like

The 9 Talents in Software Teams

The 9 Talents in Software Teams

Job titles like “Senior Engineer” or “Principal Engineer” don’t explain how someone actually contributes to a team. Counting a candidate’s years of experience doesn’t tell you whether they’ll bring stability in a crisis, explore new ideas, or quietly hold a group together when things get messy.

After leading different engineering teams and organizations, I’ve seen the same profiles appear again and again, regardless of title or tech stack. These profiles shape how teams perform, where they get stuck, and how they grow. Over time, I began to think of them as archetypes of engineering talent: Patterns of behavior and impact that show up in every healthy software team.

Read More
28 Days Later: Surviving Your First Month as a CTO

28 Days Later: Surviving Your First Month as a CTO

There’s a tired old trope in leadership circles: “Your first 100 days define your legacy.”

Cute idea. Presidential even. But let’s be real: in a tech org, 100 days is a lifetime. By the time you’re on Day 101, you’re not building credibility – you’re shambling through the hallways, moaning about roadmaps, and scaring interns. In other words: You’re already a Zombie CTO.

You don’t get 100 days. You get 28. Roughly three sprints if you’re on a 10-day cycle, and that’s all the slack you’ll ever get. If you don’t establish trust, show judgment, and land a couple of quick hits by then, you’re at best irrelevant – at worst, undead.

So here’s your 28-day survival guide – not theory, not TED-talk fluff, but field-tested tactics for how to stay alive (and keep your org alive with you).

Read More