WebObjects with Scala
What is Scala?
Scala is a modern language not unlike Groovy.
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.
Many of its features and paradigms favor multi-threaded and concurrent development which may not be unfamiliar to Objective-C developers:
Objective-C | Java | Scala | |
---|---|---|---|
Mutable/Immuable Datatypes | Collections e.g: NSArray/NSMutableArray | No | All datatypes |
Closures | Extension | No | Built-in |
Static variables | Yes | Yes | No |
Static methods/functions | Yes | Yes | No |
Weakly Typed | Strongly Typed | Strongly Typed | |
Concurrency | Grand Central Dispatch (Extension) | Threads | Actors |
Other notable features include:
Objective-C | Java | Scala | |
---|---|---|---|
Parametered methods | Yes e.g: addObject: to: | No | Yes e.g: add(object= ,to=) |
Class composition | Categories | Interfaces | Traits |
A fuller description of Scala can be found here.
Why Use Scala?
With Web 2.0, building concurrent WebObjects applications is a must.
Developing and maintaining a concurrent or multi-threaded WebObjects application can be challenging.
Scala offers concurrency built into the language and is inherently thread-safe.
So it may offer new solutions for concurrency in WebObjects.
Can WebObjects be Programmed With Scala?
Yes. It is very simple.
Scala compiles to java bytecode. Hence using it with WebObjects is fairly straightforward.
How to Develop WebObjects With Scala
- Install the Scala eclipse IDE
- Add Scala support to your WO project
- Right-click your project in the WO Explorer
- In the context menu select Scala -> Add Scala Nature
- Convert or use .scala instead of .java source
WO Scala Example
The following is a mixed Java/Scala version of the WO Movies D2W app.
All the EO logic and WO components are in Scala.
Only the Application class is Java.
Unknown macro: attachments. Click on this message for details.
Setup
- Install and run the OpenBase OBMovies database.
- Right-click on Application.java and run as a WOApplication (as usual).
EO Templates
See: Scala templates
When you create your .eogen file, be sure to make the following changes in the EOGenerator Editor:
- Change the File Names Extension to "scala"
- Uncheck Java under Options