Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Scala is a modern, multi-paradigm JVM language that is most often compared to Groovy, Clojure or and Erlang. Its functional language foundations and built-in Actors library make it especially attractive for concurrent computing. (Scala is an abbreviation for "scalable" hinting at its design goals).

In this day and age of multi-core processors concurrent computing can not be ignored. Many of the design features of Scala have been chosen with concurrency in mind, some of which may not be unfamiliar to Objective-C or WebObjects developers. Here's a summary:

 

Objective-C

Java

Scala

Immutability

Collections Partial - via collections e.g: NSArray/NSMutableArray

No

Yes

Closures

Yes - via Blocks (Extension)

No

Yes - via Anonymous Functions

Static variables

Yes

Yes

No

Static methods or functions

Yes

Yes

No

Concurrency

Yes - via Grand Central Dispatch (Extension)

Yes - via Threads

Yes - via Actors

 

Weakly Typed

Strongly Typed

Strongly Typed

...

 

Objective-C

Java

Scala

Parametered methods

Yes e.g: addObject: to:

No

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

Class composition

Yes - via Categories

Yes - via Interfaces

Yes - via Traits

Why Use Scala?

For WebObjects developers, Scala offers itself as a powerful, safe and easy-to-use solution for concurrent computing. (In other words, Scala Actors can be used for problems that would have normally required threads).

...

Code Block
java
java
public class _Talent extends EOGenericRecord {
	public static final String ENTITY_NAME	= "Talent";
}

Scala:

Code Block
object Talent {
	val ENTITY_NAME = "Talent"
}

This value will be accessed exactly the same way in both languages:

...

Code Block
java
java
public class MenuHeader extends WOComponent {

    public MenuHeader(WOContext aContext) {
        super(aContext);
    }
}

In Scala:

Code Block
class MenuHeader(context: WOContext) extends WOComponent(context: WOContext) {

Simplified Exception Handling

...

Scala Annotations vs. Generated Accessors

An Here's an example of accessing variables in WebObjects with the following languages:

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

 

Objective-C

Java

Scala

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7b116617-af9a-44fb-a822-95a304cc415b"><ac:plain-text-body><![CDATA[

getter

[WO: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="34df408c-6156-46c7-ae96-38f9338acc10"><ac:plain-text-body><![CDATA[

setter

[object setName:aName]

object.setName(aName)

object.name = aName

Of course in Java, we may generate WebObjects classes with "get" methods as well in order to stick to convention.
In scala there is an additional convenience we may use to produce "get" and "set" methods in addition to the default Scala accessors - Scala Annotations.

...

Attachments
patterns.*zip

Setup

  1. Install the Scala eclipse IDE
  2. Right-click on Application.java and run as a WOApplication (as usual).

...