Quick turnaround is a major benefit of embedding a dynamically typed language within a Java based application. Developers no longer need to restart the whole application or the entire server for certain types of changes.
Still, there are things which could be improved, including:
- Debugging Support
- Code Reuse
- Java Integration
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var nr1 = Packages.org.alfresco.service.cmr.repository.NodeRef.newInstance();
var nr2 = Packages.org.alfresco.service.cmr.repository.NodeRef.getConstructor(...).newInstance(...);
This works and gets the job done, but feels just plain wrong.
The Groovy Alternative
Groovy is really outshining the competition addressing these issues. Super smooth Java integration is baked into the language. Debugging is based on JPDA/JDI – a very mature and perfectly supported technology. Even the code providing the embedded scripting was almost where I wanted it. Spring Surf sources include an extension (spring-webscripts-addon-groovy) which has a working
The only little
hack tweak to get breakpoints working was to break Webscript naming convensions replacing the dot with an underscore. Hence
groovy_get.groovy. Today, it is just a proof of concept but it works right as I would expect. Deploy the module, attach your IDE to the process, set a breakpoint and drive the application there:
Below is a link to the sources and a ready made module just in case you’d like to try it out. Honestly, I think Groovy deserves a little more attention in the Alfresco ecosystem. I am volunteering to push a little further.
In the Alfresco Repository/Spring Surf use case, I personally think you cannot beat Groovy. The only other
ScriptProcessor I’m aware of is the Clojure based implementation. No doubt – the OOP <-> FP language border is rough, but Clojure is a beautiful language well worth it compared to … ;) Clojures REPL based development model makes it very appealing to me. I only had a quick glimpse at
lambda-alf so far, but I will definitely have another closer look soon. I would pick Clojure next because I enjoy the language – your mileage may vary.
PS: Just in case you look at my code and wonder what is going on in
I wanted to reuse all the repository
ScriptProcessor works in Surf Apps just as well. The reflection mess is just the struggle with the type system.
Update April 19, 2012:
- Forked spring-webscripts-addon-groovy at github
- Added Peters post to the references
- Alfresco module source code @ github
- Fork of spring-webscripts-addon-groovy @ github
- Alfresco and Groovy, Baby!
- Script imports with a cleaner API (Alfresco/Rhino)
- lambdalf (Clojure flavour for Alfresco)
- Image Credits
- Definition of „outshine“