Using Scala with Web Tools

I was planning to write about how to use the Scala Plugin and Web Tools together to build Scala web applications in Eclipse, but thankfully James Bayer beat me to it, so I don’t have to bother :) The title says “Scala Development with Eclipse and Weblogic”, but there’s actually nothing really Weblogic specific there — using the Jetty server included in Eclipse is quite similar.

Scala: for a/vs while

After posting about the (almost non-existent) performance impact of implicit conversions, I noticed something that blew my mind somewhat: if I used a for expression instead of while, the code ran much longer. How much? About a hundred times. Here’s a simple example, and again it’s such an example that brings out the difference between two “primitive” things taken out of context, so it doesn’t really tell us anything about real-life application performance:

object ComprehensionPerfImpact {
def main(args : Array[String]) : Unit = {
val n = 100000000

Time(“for-comprehension”) {
for (x <- 1 to n) {} } Time("while") { var x = 0 while (x <= n) { x += 1 } } } }[/sourcecode] The output:# Block “for-comprehension” completed, time taken: 16797 ms (16.797 s)
# Block “while” completed, time taken: 125 ms (0.125 s)

Update: I forgot to mention that this test was made with Scala version 2.6.0. I have also now run this on Scala 2.7.0 RC1, where the results are about 2.5 times faster.

Continue reading