small medium large xlarge

Alain_o_dea_pragsmall
12 Jul 2009, 22:47
Alain O'Dea (41 posts)

I found the first example in Chapter 3 (ScalaForTheJavaEyes/Greetings.scala) confusing because it is not compilable Scala and thus causes Scala IDE for Eclipse to flag errors in the file. It took me a couple of minute before I realized that I had to run it from the command line.

I was able to use an External Tools Configuration for running non-compilable Scala scripts in Eclipse, but I would consider that an unusual approach. Should this be considered a potential pitfall for newcomers?

Do Scala scripts not compile by purposeful design? It seems like a trivial thing to support, especially when things like Application exist that let you omit the ceremonial main function.

Alain_o_dea_pragsmall
14 Jul 2009, 01:38
Alain O'Dea (41 posts)

-Reading further I see what could be an answer: compile-time type checking isn’t done for Scala scripts.-

Not quite correct as Venkat explains below…

Venkatsubramaniam_pragsmall
13 Jul 2009, 11:59
Venkat Subramaniam (86 posts)

Alain, compile-time (type checking) errors will be reported for scripts as well. For instance, a script with such errors will not be partially run before errors are reported. Only such errors will be reported and no actual code is executed in this case.

Alain_o_dea_pragsmall
14 Jul 2009, 01:38
Alain O'Dea (41 posts)

Thank you for the answer on the type-checking Venkat :) I’m back to square one on the scripts not compiling with scalac though.

Venkatsubramaniam_pragsmall
14 Jul 2009, 03:07
Venkat Subramaniam (86 posts)

Alain, in order to compile code with scalac, you need to write either a class or a singleton object (like in section 2.7). If you are writing a script that you simply intend to run, use scala to run it. If you are writing Scala code that you intend to use with other Scala or Java code, then you can place it in a class or object and compile it using scalac. So, whether you use scala or scalac depends on the intent.

  You must be logged in to comment