Changes for page WebObjects with Scala

Last modified by Ravi Mendis on 2011/05/10 02:10

From version 435.1
edited by Ravi Mendis
on 2010/09/09 23:13
Change comment: There is no comment for this version
To version 438.1
edited by John Huss
on 2010/12/03 16:40
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.rmendis
1 +XWiki.johnthuss
Content
... ... @@ -1,9 +1,9 @@
1 1  === What is Scala? ===
2 2  
3 -[[Scala>>http://en.wikipedia.org/wiki/Scala_(programming_language)]] is a language for concurrent computing.
3 +[[Scala>>http://en.wikipedia.org/wiki/Scala_(programming_language)]] is a JVM language that is a hybrid of Object-Oriented and Functional styles.  It is useful as complete general purpose replacement for Java.  But its built-in Actors library makes it especially attractive for concurrent computing.
4 4  In this day and age of multi-core processors, concurrent computing can't be ignored.
5 5  
6 -Many of Scala's features have been designed with concurrency in mind.
6 +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.
7 7  Some of these may not be unfamiliar to Objective-C or WebObjects developers.
8 8  
9 9  Here's a quick summary:
... ... @@ -24,8 +24,8 @@
24 24  
25 25  === Why Use Scala? ===
26 26  
27 -Scala is inherently thread-safe.
28 -It has concurrency that is effectively built-in to the language.
27 +Scala can help you to write thread-safe code.
28 +It has concurrency that is built-in to the standard library, primarily via Actors.
29 29  
30 30  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).
31 31  
... ... @@ -42,7 +42,7 @@
42 42  
43 43  === Thread-Safe Shared Vars ===
44 44  
45 -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.
45 +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 singletons
46 46  
47 47  So you don't have to worry about synchronizing access to shared mutable fields in a concurrent application.
48 48  
... ... @@ -188,27 +188,10 @@
188 188  
189 189  == How to Use Scala Collections with EOF ==
190 190  
191 -One of the benefits of Scala is its very powerful, concurrency-ready collection classes - primarily ##List##, ##Map## and ##Set##.
192 -Employing these instead of ##NSArray## and ##NSDictionary## in WebObjects/EOF may be challenging.
191 +To use the Scala Collections API with an NSArray or NSDictionary you simply need to add an import:import scala.collection.JavaConversions.
193 193  
194 -But one may modify the EO templates to produce API such as:
193 +Then you can access the typical Scala collection methods directly on NSArray.  This employs a feature of Scala known as implicit conversions to automagically cast a NSArray (a Java Iterable) into a Scala Iterable while leaving the actual object unchanged.  Alternatively, you could generate an actual new scala.List instance by calling myNSArray.toList.
195 195  
196 -{{code}}
197 -
198 -import scala.collection.JavaConversions._
199 -
200 -def movies = {
201 - storedValueForKey(_Studio.Keys.MOVIES).asInstanceOf[NSArray[Movie]]
202 -}
203 -
204 -def moviesList = {
205 - movies.asInstanceOf[java.lang.Iterable[Movie]].toList
206 -}
207 -
208 -{{/code}}
209 -
210 -This employs a feature of Scala known as **implicit conversions** to automagically convert a NSArray (a Java Iterable) into a Scala Iterable.
211 -
212 212  == How to Add Scala to a WO Project ==
213 213  
214 214  {{include value="WOL:Adding Scala Support to a WOLips Project"}}{{/include}}
... ... @@ -234,6 +234,8 @@
234 234  1. [[Install the Scala eclipse IDE>>http://www.scala-ide.org/]]
235 235  1. Right-click on Application.java and run as a WOApplication (as usual).
236 236  
220 +Application can be made into a Scala class as well, but then you will have to create a launcher in Eclipse manually.
221 +
237 237  == EO Templates ==
238 238  
239 239  When you create your ##.eogen## file, be sure to make the following changes in the EOGenerator Editor: