Changes for page WebObjects with Scala
Last modified by Ravi Mendis on 2011/05/10 02:10
From version 444.1
edited by John Huss
on 2010/12/03 16:45
on 2010/12/03 16:45
Change comment:
There is no comment for this version
To version 448.1
edited by Ravi Mendis
on 2010/12/23 23:48
on 2010/12/23 23:48
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. johnthuss1 +XWiki.rmendis - Content
-
... ... @@ -1,15 +1,11 @@ 1 1 === What is Scala? === 2 2 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 -In this day and age of multi-core processors, concurrent computing can't be ignored. 3 +[[Scala>>http://en.wikipedia.org/wiki/Scala_(programming_language)]] is a JVM language that is a hybrid of Object-Oriented and Functional styles. Its [[functional language>>http://en.wikipedia.org/wiki/Functional_programming]] foundations and built-in Actors library makes it especially attractive for concurrent computing. In this day and age of multi-core processors concurrent computing can not be ignored. 5 5 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 -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: 8 8 9 -Here's a quick summary: 10 - 11 11 |= |= Objective-C |= Java |= Scala 12 -|= Separation of Mutable &Immuable Datatypes| Collections //e.g: NSArray/NSMutableArray// | No | Yes8 +|= Immutability | Collections //e.g: NSArray/NSMutableArray// | No | Yes 13 13 |= Closures | Blocks (//Extension//) | No | Anonymous Functions 14 14 |= Static variables | Yes | Yes | No 15 15 |= Static methods or functions | Yes | Yes | No ... ... @@ -32,10 +32,14 @@ 32 32 === Can WebObjects be Programmed In Scala? === 33 33 34 34 Yes. It is very simple. 35 -Scala compiles to java bytecode. Hence using it with WebObjects is fairly straightforward.31 +Scala compiles to java bytecode. 36 36 37 - 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 is ratherslowand still verybuggy.33 +Furthermore, being a multi-paradigm language grants Scala easy WebObjects-interoperability. 38 38 35 +===== Caveats ===== 36 + 37 +Tool support is 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]] is rather slow and still very buggy. 38 + 39 39 = WebObjects In Scala = 40 40 41 41 The following highlights some of the differences between Java and Scala in WebObjects: ... ... @@ -190,10 +190,16 @@ 190 190 191 191 == How to Use Scala Collections with EOF == 192 192 193 -To use the Scala Collections API with an NSArray or NSDictionary you simply need to add an import: import scala.collection.JavaConversions.193 +To use the Scala Collections API with an NSArray or NSDictionary you simply need to add an import: 194 194 195 - Then youcan access the typical Scala collection methods directlyon NSArray. This employs a feature of Scala known as implicit conversions toautomagically 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 +{{code value="java"}} 196 196 197 +import scala.collection.JavaConversions._ 198 + 199 +{{/code}} 200 + 201 +After that, you may 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. 202 + 197 197 == How to Add Scala to a WO Project == 198 198 199 199 {{include value="WOL:Adding Scala Support to a WOLips Project"}}{{/include}}