JavaOne

EnfranchisedMind's Adventures at JavaOne 

Modularity: JSR-294 and Beyond 2

Example:
 
On file system --
planetjdk/src/
  org/planetjdk/aggregator
  module-info.java
 
Inside the file module-info.java:
 
module org.planetjdk.aggreator {
  system jigsaw; // Parent structure
  requires module jdom; // Classpath requirement
  require module tagsoup; // Classpath requirement
  ...
  class org.planetjdk.aggregator.Main; // Exported class
}
 
 
 
Interestingly, the module-info.java compiles to module-info.class.

Loading mentions Retweet

Comments [0]

Modularity: JSR-294 and Beyond 1

JSR-294 is the language changes to support module systems. Jigsaw is a client of JSR-294 providing a module system. OpenJDK's Project Jigsaw is the reference implementation of JSR-294 and drives the Jigsaw design/impl. JSR-294 is itself *not* a module system.
 
Modular code:
1) Clarifies code dependencies (by explicitly listing its dependencies)
2) Can evolve without breaking clients (by explicitly versioning itself and its dependencies)
3) Can hide its internals from other modular codes (by making classes 'module-private')
 
It's a static typing information ("static typing++"), and allows to detect at compile time what might otherwise be caught at runtime.

Loading mentions Retweet

Comments [0]

State: You're Doing It Wrong

Jonas Boner (JBoner on Twitter and GitHub), featuring Clojure and Scala prominantly. Similar to my "Architecting Concurrency" talk (except I have cooler graphs and Star Trek pictures). Also introduced the idea of "Dataflow Concurrency", which is a generalization of the traditional producer-consumer approach and bears a startling resemblance to the simpler usages of the join calculus. It's apparently used mainly in Oz, and his Java library (which is built on top of Scala actors).
 
Walked through a banking account example for shared memory and STM, a ping-poing example for actors, and then demonstrated simple dataflow concurrency:
 
def x,y,z = new DataFlowVariable[Int]
thread { z thread { x thread { y 93 }

Loading mentions Retweet

Comments [0]

Oz is a recommended Language for dataflow concurrency.

Posted from my mobile phone (SMS)

Loading mentions Retweet

Comments [0]

Feel of Scala 7

Now going into duck typing in matchers, based on "view bounds". This defines a can-be-treated-as relationship. Translations have to be defined from all objects, though, and that's hassle. To solve this, use structural types:
 
{ val length: Int } -- anything with a field of length
{ def length(): Int } -- anything with a method of length
etc.
 
This creates compile-time checked duck typing.

Loading mentions Retweet

Comments [0]

Feel of Scala 6

To test for thrown exceptions, ScalaTest can use this:

 intercept[StringIndexOutOfBoundsException] {
  s.charAt(-1)
}

 The square brackets are type annotations. Scala and Java both use the erasure model, so how does it know what time it is at compile time? It's possible to ask Scala for "reified types".

 Tests in ScalaTest are functions that take a string description and a body [akin to RSpec/EasyB -ed.]. There's an explicit RSpec clone with nicer documentation, too.

 Scala also has symbol literals, which are strings and used to talk about the code. [Totally lost him at this point: couldn't figure out what was special about his code. -ed.]

Loading mentions Retweet

Comments [0]

Feel of Scala 5

The "if" statement has an implicit return, so it is a hybrid between Java's "if" and its ternary operator.
 
He then launched into currying.
 
def max(a:Int, b:Int) = if (a>b) a else b
 
def max(a:Int)(b:Int) = if (a>b) a else b
 
max(3,5) now fails, but max(3)(5) now works. max(3){5} also works, which makes it look like a control structure. So to define our expect statement:
 
def expect(expected:Any)(actual:Any) {
  if (expected != actual) throw new AssertionError()
}
 
expect(3) { 1 + 2 } // Works fine
expect(5) { 1 + 7 } // Throws AssertionError
 
Voila -- a new control structure [looking thingy -ed]!

Loading mentions Retweet

Comments [0]

Feel of Scala 4

Introduced open classes. Venners argues that implicit conversions gives open class like capabilities.
 
map should contain --> map.should(contain)
map should contain key ('a') --> map.should(contain).key('a')
 
To accomplish what open classes gives you, create an implicit conversion to a class that has the method you'd like to add. The implicit conversion is applied if one and only one conversion is found. The rules are very strict because they can be confusing.
 
The rules are:
1) You have to invite in implicit conversions through importing or inheriting them.
2) Only one type is accepted.
3) It cannot be nested inside properties: has to be a top-level identifier.
 
ScalaTest provides a === method, which reports meaningful messages when there are errors.
 
Also provides a syntax to clarify what's expected and actual in an assert.
expect(myKitty) { animalShelter.getCat() }

Loading mentions Retweet

Comments [0]

Feel of Scala 3

You should get about half the lines of code of Scala as compared to Java, as long as you are calling Scala libraries from Scala code. Scala code calling Java library still has to use Java API. Standard behavior is to replace them.
 
Scala rewrites:
factorial(x-1) to factorial(x.-(1)) [[ The "-" is a method with an operator name. ]]
map containsKey 'a' to map.containsKey('a') [[ The space notation is used in subj-verb-obj. ]]

Loading mentions Retweet

Comments [0]

Feel of Scala 2

Static typing offers deterministic refactoring, requires fewer tests, lighter documentation, gives better code completion, and offers more performance. Scala gives all of these things. [This is Bill Venners's take, not mine. -ed]

Loading mentions Retweet

Comments [0]