views:

102

answers:

4

How do YOU debug a Scala program?

I mean YOU as in the person posting the Answer :) Please answer only from personal experience, not from stuff you've heard or read on the Internet. You should not believe everything you read on the Internet, especially tales of complex open-source software configurations that actually work :-)

The are many Java tools which claim to support Scala in some way or another, but I have so far struck out in trying to get any one of them to actually let me set a breakpoint in Scala code and step through it. These are big, major open-source IDEs I'm talking about here.

The main problem in getting a debugger to work seems to be the "version hell" with fast-changing IDEs, Plug-Ins, JDKs, and the Scala language itself.

Hence, the more detailed re-statement of the question is appropriate: What is the exact version number of the IDE, Plug-In, JDK, Scala, and even Operating System, that you are successfully using?

My question is related to this one, but wider in scope: http://stackoverflow.com/questions/2272705/how-to-debug-scala-code-when-outside-of-an-ide

Thanks

+2  A: 

Hello,

In our development we use IntelliJ IDEA 9.0.1 which is available by the link below:

http://www.jetbrains.com/idea/download/

with Scala plugin installed:

http://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin

All you need is to have project with Scala sources (probably, mixed with Java or other JVM-based languages) opened. You can compile it and run as Java application, maven goal etc. or connect to the remote application if it has been run in debug mode. See IntelliJ help for details of adjusting debug configuration.

Cheers!

Ilya

Ilya Sergey
Thanks, the linked instructions works.. but I guess only if I pick Scala 2.7.3 from the drop-down? Because I tried yesterday with 2.7.6 and also 9.0.2 EA with 2.8.0beta1, and it didn't work! Thanks
Alex R
Alex,What kind of problem is observed if you try to debug your code with Scala 2.8?If you need to debug scala library source, you should have them attached to your module libraries. Debugging ability doesn't really depend on particular version of Scala distribution and it must work with 2.8 as well.Cheers!Ilya
Ilya Sergey
with 2.8 the IDE could not even find scalac - despite the scala-*.jars being in the right place and all settings checked.
Alex R
A: 

I debug my Scala programs by running relevant parts of it on the REPL, as to verify what it is really doing. Other than that, the good old println or logs.

Digressing here a bit, it has been a rare thing in my life a situation where step-in debuggers were actually required -- and, then, mostly for assembler code, though languages where testing snippets of code is difficult for some reason were more likely to require it than others which weren't.

Daniel
I'd say step debugging and trace debugging complement each other. I know I use both. ... Not at the same time (usually).
Randall Schulz
Step debugging works best when you don't yet have a full understanding of the language and run-time environment.
Alex R
@Alex: +1 on that!
Daniel
A: 

OS: xUbuntu(GNU/Linux) 9.10

JDK:

java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

(which is the Java-6-sun-version, used by the xUbuntu-installer).

Eclipse: 3.5.1 Build id: 20090920-1017

Scala-Plugin 2.7.7final

Scala 2.7.7

If possible: println-Statements, because eclipse is often tricky to invoke (does not find the main class, even after complete rebuild, closing/opening project, deleting old class-Files). The latest search for a problem ended when I 'deleted all bookmarks' - suddenly I was allowed to run the program.

Curious observation: class Bruch was what I tried to run, but eclipse allways mentioned 'Bruc' and named the runtime-configuration like this. Adding and removing characters reflected in the generated name accordingly (Bruc => Bru).

user unknown
+1  A: 

I've worked with Eclipse and the Scala plugin for it. It works somewhat ok, if you can overlook the fact that it doesn't remember the configuration for your Scala application on the next run.

Geo