Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

 

Objective-C

Java

Scala

Parametered methods

Yes e.g: addObject: to:

No

Yes e.g: add(object= ,to=)

Class composition

Categories

Interfaces

Traits

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

Wiki Markup
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.

...

 

Objective-C

Java

Scala

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ee584499a645d5e2-45373b20-43794e47-b5b5b42a-1280f8fdb3b55f7660415694"><ac:plain-text-body><![CDATA[

getter

[object name]

object.name()

object.name

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="010c59aadc4ce1a8-aa5d3eef-45ae457b-88b68673-1e7f95f6cf3cceb5ceacca85"><ac:plain-text-body><![CDATA[

setter

[object setName:aName]

object.setName(aName)

object.name = aName

]]></ac:plain-text-body></ac:structured-macro>

...

How to Use Scala Collections with EOF

One of To use the benefits of Scala is its very powerful, concurrency-ready collection classes - primarily List, Map and Set.
Employing these instead of NSArray and 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._

...

This

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

...

  1. Install the Scala eclipse IDE
  2. 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.

EO Templates

When you create your .eogen file, be sure to make the following changes in the EOGenerator Editor:

...