Wiki source code of WebObjects with Scala
Version 246.1 by Ravi Mendis on 2009/09/15 22:37
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | === What is Scala? === | ||
2 | |||
3 | Scala is a modern language not unlike Groovy. | ||
4 | It is said to be more powerful (and faster) than Groovy or Rails which has been the reason for its adoption at sites like Twitter. | ||
5 | |||
6 | Many of its features and paradigms favor multi-threaded and concurrent development which may not be unfamiliar to Objective-C developers. | ||
7 | Here's a summary: | ||
8 | |||
9 | |= |= Objective-C |= Java |= Scala | ||
10 | |= Mutable/Immuable Datatypes | Collections //e.g: NSArray/NSMutableArray// | No | //All datatypes// | ||
11 | |= Closures | Blocks (//Extension//) | No | //Built-in// | ||
12 | |= Static variables | Yes | Yes | No | ||
13 | |= Static methods/functions | Yes | Yes | No | ||
14 | |= Concurrency | [[Grand Central Dispatch>>http://en.wikipedia.org/wiki/Grand_Central_Dispatch]] (//Extension//)| //Threads// | Actors | ||
15 | |= |= Weakly Typed |=--Strongly Typed--|= Strongly Typed | ||
16 | |||
17 | Other notable features include: | ||
18 | |||
19 | |= |= Objective-C |= Java |= Scala | ||
20 | |= Parametered methods | Yes //e.g: addObject: to~:// | No | Yes //e.g: add(object= ,to=)// | ||
21 | |= Class composition | Categories | Interfaces | Traits | ||
22 | |||
23 | A fuller description of Scala can be found [[here>>http://en.wikipedia.org/wiki/Scala_(programming_language)]]. | ||
24 | |||
25 | === Why Use Scala? === | ||
26 | |||
27 | With Web 2.0, building concurrent WebObjects applications is a must. | ||
28 | Developing and maintaining a concurrent or multi-threaded WebObjects application can be challenging. | ||
29 | |||
30 | Scala offers concurrency that is (effectively) built-in to the language and is inherently thread-safe. | ||
31 | So it may offer new solutions for concurrency in WebObjects. | ||
32 | |||
33 | === Can WebObjects be Programmed In Scala? === | ||
34 | |||
35 | Yes. It is very simple. | ||
36 | Scala compiles to java bytecode. Hence using it with WebObjects is fairly straightforward. | ||
37 | |||
38 | == How to Develop WebObjects In Scala == | ||
39 | |||
40 | 1. [[Install the Scala eclipse IDE>>http://www.scala-lang.org/node/94]] | ||
41 | 1. Add Scala support to your WO project | ||
42 | 11. Right-click your project in the WO Explorer | ||
43 | 11. In the context menu select Scala -> Add Scala Nature | ||
44 | 1. Convert or use ##.scala## instead of ##.java## source | ||
45 | |||
46 | {{note title="Note"}} | ||
47 | |||
48 | This is for Eclipse/WOLips IDE | ||
49 | |||
50 | {{/note}} | ||
51 | |||
52 | == WO Scala Example == | ||
53 | |||
54 | The following is a mixed Java/Scala version of the WO Movies D2W app. | ||
55 | All the EO logic and WO components are in Scala. | ||
56 | Only the Application class is Java. | ||
57 | |||
58 | {{attachments patterns=".*zip"}}{{/attachments}} | ||
59 | |||
60 | === Setup === | ||
61 | |||
62 | 1. Install and run the OpenBase OBMovies database. | ||
63 | 1. Right-click on Application.java and run as a WOApplication (as usual). | ||
64 | |||
65 | ==== EO Templates ==== | ||
66 | |||
67 | See: [[Scala templates>>http://wiki.objectstyle.org/confluence/display/WOL/EOGenerator+Templates+and+Additions]] | ||
68 | |||
69 | When you create your ##.eogen## file, be sure to make the following changes in the EOGenerator Editor: | ||
70 | |||
71 | 1. Change the File Names Extension to "scala" | ||
72 | 1. Uncheck Java under Options |