What is Scala?
Scala 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.
In this day and age of multi-core processors, concurrent computing can't be ignored.
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.
Some of these may not be unfamiliar to Objective-C or WebObjects developers.
Yes e.g: addObject: to:
Yes e.g: add(object= ,to=)
Why Use Scala?
Scala is inherently can help you to write thread-safe code.
It has concurrency that is effectively built-in to the languagestandard library, primarily via Actors.
So for WebObjects developers, Scala offers itself as a powerful, safe and easy-to-use solution for concurrent applications. (In other words, Scala Actors can be used for problems that would have normally required threads).
EOs in Scala
Thread-Safe Shared Vars
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\]
So you don't have to worry about synchronizing access to shared mutable fields in a concurrent application.
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c65ddaaa48d550cc-d393af24-437444c3-83878bf2-23dc775faaefa6594f3a4103"><ac:plain-text-body><![CDATA[
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="40f289985ac70256-fcae3c61-423c4e00-8be2a2cd-6b8e675ebf9926fa6a01b0f9"><ac:plain-text-body><![CDATA[
How to Use Scala Collections with EOF
One of To use the benefits of Scala is its very powerful, concurrency-ready collection classes - primarily
Employing these instead of
NSDictionary in WebObjects/EOF may be challenging.
But one may modify the EO templates to produce API such as:
Scala Collections API with an NSArray or NSDictionary you simply need to add an import:import scala.collection.JavaConversions._
Then you can access the typical Scala collection methods directly on NSArray. This employs a feature of Scala known as implicit conversions to automagically convert 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.
How to Add Scala to a WO Project
- Install the Scala eclipse IDE
- Right-click on Application.java and run as a WOApplication (as usual).
Application can be made into a Scala class as well, but then you will have to create a launcher in Eclipse manually.
When you create your
.eogen file, be sure to make the following changes in the EOGenerator Editor: