SCALA VS JAVA :
Here's a list of what a Java guy should know about Scala:
Scala programs are byte-code compatible with Java code. Scala code can call Java code, implement Java interfaces, subclass Java classes and can be called from Java code. The guy who wrote the Scala compiler wrote JavaC. Really, they work perfectly together and Scala code runs as fast as Java code.
Scala code is more compact and more expressive. For example:
List tmp = new ArrayList();
for (Other tmpOther : otherList) {
tmp.add(new Foo(tmpOther));
}
becomes:
otherList.map{i => new Foo(i)}
The creation of the temporary variable for the returned array is done implicitly (and it's strongly typed.) You worry about how to "map" one array to another rather than spending time declaring temporary variables or describing looping. Note that you didn't have to "type" anything. Scala is strongly typed, just like Java, but if the compiler can figure it out, you don't need to repeat the typing information.
You can write code the way you used to and migrate to "functional" thinking as your brain shifts. It's not a dive into the deep end like Haskell or OCaml. The initial learning curve is short and the continued learning curve is gradual. Plus, most other Java coders can look at your Scala code and understand it until you get into some pretty hardcore Scala constructs.
XML is an integral part of Scala. XML is legal syntax within the language. For example:
def addressNode(line1 : String,line2 : String, city : String, state : String, country : String) = {
for (Other tmpOther : otherList) {
tmp.add(new Foo(tmpOther));
}
becomes:
otherList.map{i => new Foo(i)}
The creation of the temporary variable for the returned array is done implicitly (and it's strongly typed.) You worry about how to "map" one array to another rather than spending time declaring temporary variables or describing looping. Note that you didn't have to "type" anything. Scala is strongly typed, just like Java, but if the compiler can figure it out, you don't need to repeat the typing information.
You can write code the way you used to and migrate to "functional" thinking as your brain shifts. It's not a dive into the deep end like Haskell or OCaml. The initial learning curve is short and the continued learning curve is gradual. Plus, most other Java coders can look at your Scala code and understand it until you get into some pretty hardcore Scala constructs.
XML is an integral part of Scala. XML is legal syntax within the language. For example:
def addressNode(line1 : String,line2 : String, city : String, state : String, country : String) = {
{if (line2 != null)
}
How about counting all the addresses that are from a particular country:
def countryCount(toMatch : String, xml : Seq[Node]) = {
(for (val addr <- xml \\ "address";
val country <- addr \\ "country" ;
country.text == toMatch)
yield country).length
}
Note that other than the "\\" to look for nodes in an XML document, everything else makes "sense." The "\\" "operator" is not part of the language, but a method on XML Nodes (and sequences of Nodes), but the compiler "does the right thing" and makes the 'node \\ string' construct readable and (IMHO) natural. You can look at the code as a Java guy and understand what it does without freaky loop constructs, intermediate variables for XPath, etc.
Put another way, the English description and the code match each other:
for each of the address tags
find the country tag
if the country matches, yield it to the length (count)
Mixins/Traits
Ever wish you could add methods to an interface so that every class that implemented the interface got those methods for free? Interfaces bring constants, but not methods in Java. Scala has "traits" which all your to define functions (what Java calls methods) and variables that get automatically added to classes when you extend the class with the trait. It's an excellent form of code re-use.