Pure4J: Compile-Time Functional Purity and Immutability for the Java Language
github.com
github.com
EDIT: actually predating that JSR, coming from here http://jcip.net/annotations/doc/index.html
First, the contract is slightly different, as I am also asserting purity. This means that one @ImmutableValue knows that another @ImmutableValue (perhaps from a library package) is pure. Whereas, a class annotated with @Immutable might not be.
Second, I developed this with the bank I work in in mind. They are still on flavours of Java 6 + 7.
However, I am currently in mind to port this to Checker Framework, http://types.cs.washington.edu/checker-framework/ which is fully supported by the JDK8 compiler.
I expect I'll still keep the separate annotation, but there are a lot of benefits from a tooling point of view to doing this (IDE support, gradle etc)
Awesome! Checker is very promising. Unfortunately, its developers have not yet (I think) turned their efforts into making it as easy to use as possible (it could be made very easy to use, but that would take some effort).
In the Clojure world, (and indeed in Haskell and other pure-fp languages) there is a lot more garbage collection. Rich Hickey makes a great case for this trade off here [2].
On the JVM now very little of it is stop-the-world GC, it mostly does incremental. It's been a while since I profiled a Java app in anger, but even back on JDK5 this was the case, and I know they changed it significantly in JDK7 to the G1 collector.. anyone have a clue about that?
[1] https://github.com/robmoffat/pure4j/blob/master/docs/tutoria... [2] http://www.infoq.com/presentations/Value-Values [3] http://www.oracle.com/webfolder/technetwork/tutorials/obe/ja...
http://stackoverflow.com/questions/11332239/is-it-possible-t...
http://stackoverflow.com/questions/5331422/marking-an-object...
1. Very conservative (I hope). As to exactly what this means, the specs are here: http://robmoffat.github.io/pure4j/concordion/org/pure4j/test...
2. Not the whole program, but "islands of purity". i.e. classes or hierarchies of classes which are annotated with @Pure/@ImmutableValue/@MutableUnshared (see above for what these mean, exactly).
3. At compile time, it builds a model of your software by analysing the byte-code. It should run in linear time I guess but I haven't tried it on any huge codebases yet. At runtime, the performance will be heavily dependent on the performance of the Clojure collections that I've imported.
But yes, I think this is a workable idea - so long as there was some way of identifying 3rd-party code purity instead of the annotation.