Changes for page WebObjects with Scala
Last modified by Ravi Mendis on 2011/05/10 02:10
From version 454.1
edited by Ravi Mendis
on 2010/12/23 06:51
on 2010/12/23 06:51
Change comment:
There is no comment for this version
To version 457.1
edited by Ravi Mendis
on 2010/12/24 00:26
on 2010/12/24 00:26
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,14 +1,11 @@ 1 1 === What is Scala? === 2 2 3 -[[Scala>>http://en.wikipedia.org/wiki/ Scala_(programming_language)]]is a JVMlanguagethatsahybridof Object-Oriented andFunctionalstyles. Itisuseful ascompletegeneralurposereplacementfor Java. Butts built-in Actors library makes it especially attractive for concurrent computing. In this day and age of multi-core processors,concurrent computing can't be ignored.3 +[[Scala>>http://www.scala-lang.org/]] is a modern, multi-paradigm JVM language that is most often compared to [[Groovy>>http://en.wikipedia.org/wiki/Groovy_(programming_language)]], [[Clojure>>http://en.wikipedia.org/wiki/Clojure]] or [[Erlang>>http://en.wikipedia.org/wiki/Erlang_(programming_language)]]. Its [[functional language>>http://en.wikipedia.org/wiki/Functional_programming]] foundations and built-in Actors library makes it especially attractive for concurrent computing. (Scala is an abbreviation for "scalable" hinting at its design goals). In this day and age of multi-core processors concurrent computing can not be ignored. 4 4 5 -Many of Scala's features have been designed with concurrency in mind, primarily a preference for immutability and the use of other functional language paradigms. 6 -Some of these may not be unfamiliar to Objective-C or WebObjects developers. 5 +Many of Scala's features have been designed with concurrency in mind, some of which may not be unfamiliar to Objective-C or WebObjects developers. Here's a summary: 7 7 8 -Here's a quick summary: 9 - 10 10 |= |= Objective-C |= Java |= Scala 11 -|= Separation of Mutable &Immuable Datatypes| Collections //e.g: NSArray/NSMutableArray// | No | Yes8 +|= Immutability | Collections //e.g: NSArray/NSMutableArray// | No | Yes 12 12 |= Closures | Blocks (//Extension//) | No | Anonymous Functions 13 13 |= Static variables | Yes | Yes | No 14 14 |= Static methods or functions | Yes | Yes | No ... ... @@ -23,18 +23,19 @@ 23 23 24 24 === Why Use Scala? === 25 25 26 -Scala can help you to write thread-safe code. 27 -It has concurrency that is built-in to the standard library, primarily via Actors. 23 +For WebObjects developers, Scala offers itself as a powerful, safe and easy-to-use solution for [[concurrent computing>>Building Concurrent Applications with WebObjects and Scala]]. (In other words, Scala Actors can be used for problems that would have normally required threads). 28 28 29 -So for WebObjects developers, Scala offers itself as a powerful, safe and easy-to-use solution for [[concurrent applications>>Building Concurrent Applications with WebObjects and Scala]]. (In other words, Scala Actors can be used for problems that would have normally required threads). 30 - 31 31 === Can WebObjects be Programmed In Scala? === 32 32 33 33 Yes. It is very simple. 34 -Scala compiles to java bytecode. Hence using it with WebObjects is fairly straightforward.28 +Scala compiles to java bytecode. 35 35 36 - However, tool supportis a weak point. You should useEclipse 3.6 withbundle-less WO builds. Ifyour Applicationclass is in Scalathen you will have to create an Eclipselaunch configuration manually. Oneweird thingis that once you addtheScalanaturetoa WOprojectWOD completion willstop working-this is unfortunate. Alsothe [[Scalaplugin>>http://www.scala-ide.org]] is rather slow and still verybuggy.30 +Furthermore, being a multi-paradigm language grants Scala easy WebObjects-interoperability. 37 37 32 +===== Caveats ===== 33 + 34 +Legacy tool support is often cited as a weak point. If your Application class is in Scala then you will have to create an Eclipse launch configuration manually. Also the [[Scala plugin>>http://www.scala-ide.org]] can be slow at times and sometimes buggy. 35 + 38 38 = WebObjects In Scala = 39 39 40 40 The following highlights some of the differences between Java and Scala in WebObjects: ... ... @@ -43,9 +43,10 @@ 43 43 44 44 === Thread-Safe Shared Vars === 45 45 46 -Scala doesn't have static variables or methods. Instead Scala employs the [[Singleton Pattern>>http://en.wikipedia.org/wiki/Singleton_pattern]] which is built into the language and is **thread-safe**: a class can have a //Companion Object// that will allow you to achieve something equivalent to static variables - but better. Is this true? I don't think Scala "object" instances (with the object keyword) are guaranteed to be thread-safe; they are just singletons44 +Scala doesn't have static variables or methods. Instead Scala employs the [[Singleton Pattern>>http://en.wikipedia.org/wiki/Singleton_pattern]] which is built into the language and is **thread-safe**: a class can have a //Companion Object// that will allow you to achieve something equivalent to static variables - but better. 47 47 48 -So you don't have to worry about synchronizing access to shared mutable fields in a concurrent application. 46 +You don't have to worry about synchronizing access to shared mutable fields in a concurrent application. 47 +This is not however true for mutable ##val## e.g: ##NSMutableArray##, ##scala.collection.mutable.ListBuffer## which you will have to synchronize the adding to or removing from. 49 49 50 50 The following is an example of the use of a //Companion Object// for Talent in Scala instead of Talent static fields in Java. 51 51 ... ... @@ -224,8 +224,12 @@ 224 224 1. [[Install the Scala eclipse IDE>>http://www.scala-ide.org/]] 225 225 1. Right-click on Application.java and run as a WOApplication (as usual). 226 226 226 +{{note}} 227 + 227 227 Application can be made into a Scala class as well, but then you will have to create a launcher in Eclipse manually. 228 228 230 +{{/note}} 231 + 229 229 == EO Templates == 230 230 231 231 When you create your ##.eogen## file, be sure to make the following changes in the EOGenerator Editor: