We believe the purest and more functional your code is, the less
you'll need to debug it. However, you may need to at some point, in
which case you'll have to choose an adequate method depending on
the system you're developing. It could be a standalone SBT based
background job, a web application such as Play, or part of an Akka
based system.
In this section we will outline some of the standard techniques
available in the Scala ecosystem today. If you don't feel ashamed
to claim that println is the golden hammer of
debugging, then you'd probably want to jump directly to the
Logging section below and skip the first few
items.
If not, let's get started:
- Scala Worksheet
Use Scala Worksheet to debug parts of your code. Copy & Paste -
yes, but since you're in the functional world, it should be easier
to test independent components in isolation.
Eclipse: To create a worksheet in the Scala IDE,
right click on a Scala project and choose: New > Scala
WorkSheet. The rest will be obvious.
IntelliJ works similarly, and you'll find more
details here.
- REPL
Here is a nice explanation of how to run Scala
in several ways, including the REPL and the aforementioned Scala
worksheet. Note that we can use import statements to bring in your
existing code, which make it easier to play around with existing
code in your project.
- IDE/Remote Debugger
Eclipse: Scala IDE has a built-in Scala debugger,
find details here.
IntelliJ: To debug Scala code, take a look at
this. If you run into any issues, the following
StackOverflow thread might be helpful.