- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Groovy + Java + Scala
Tue, 2009-03-03, 06:08
Copying from http://www.nabble.com/Groovy%2BJava%2BScala-td22298741.html#a22298741
http://www.nabble.com/Groovy%2BJava%2BScala-tp22298741p22298741.html
Date: Mar 02, 2009; 02:53pm
Author: Alex Tkachman
groovy - dev (http://www.nabble.com/groovy---dev-f11868.html)
Almost to years ago I've invented and then wrote joint compiler for Groovy and Java. The idea was pretty simple - we do compilation in 3 steps
1) Generate Java stubs from Groovy sources
2) Compile all Java code with generated stubs
3) Compile Groovy code with already compiled Java classes
First implementation was done as part of IntelliJ and later another one was written to contribute in Groovy compiler infrastructure. Thanks a lot to Jochen and other guys who improved and incorporated it in to groovyc and ant tasks. It became probably last cornerstone for 100% interoperability between Groovy and Java and now understood by everybody as natural as if it was in Groovy from day one.
But now my arsenal includes Scala as well. Obviously I want to have Groovy and Scala and of course Java together. Isn't it natural wish?
Fortunately scala compiler is smart as well and knows how to do joint compilation with Java. Scala does it a bit differently than Groovy - by parsing Java source during Java compilation. So the process looks like following
1) Compile Scala code using Java sources on the way
2) Compile Java sources using already compiled scala classes
Unfortunally (but not surprisingly) scala has no clue about Groovy.
Today I realized that the small modification of my original algorythm + scala compiler can create joint compiler for all three languages together. The complete algorithm is following
1) Generate Java stubs from Groovy sources
2) Compile Scala code using Java sources and generated stubs on the way
3) Compile all Java code with generated stubs and compiled Scala classes
4) Compile Groovy code with already compiled Java classes
I believe you will not be surprised that when I knew what I want to do it was pretty easy to implement. In fact it was mostly refactoring of what we did before. So now in my working copy I can compile Groovy+Java+Scala together. Of course all references in all three languages are resolved correctly in all possible direction.
I think it opens many amazing opportunities of Groovy becoming orchestration language for people who needs both static and dynamic typing plus functional programming. Of course I would like to see it as part of Groovy Core.
I would like to learn what other people think about it. Please let me know.
Also if we decide to go forward with it I will need help from some ANT expert to incorporate such change in to groovy ant tasks. Any volonteers?
Alex
Free Forum — Powered by Nabble
http://www.nabble.com/Groovy%2BJava%2BScala-tp22298741p22298741.html
Groovy+Java+Scala
Date: Mar 02, 2009; 02:53pm
Author: Alex Tkachman
groovy - dev (http://www.nabble.com/groovy---dev-f11868.html)
Almost to years ago I've invented and then wrote joint compiler for Groovy and Java. The idea was pretty simple - we do compilation in 3 steps
1) Generate Java stubs from Groovy sources
2) Compile all Java code with generated stubs
3) Compile Groovy code with already compiled Java classes
First implementation was done as part of IntelliJ and later another one was written to contribute in Groovy compiler infrastructure. Thanks a lot to Jochen and other guys who improved and incorporated it in to groovyc and ant tasks. It became probably last cornerstone for 100% interoperability between Groovy and Java and now understood by everybody as natural as if it was in Groovy from day one.
But now my arsenal includes Scala as well. Obviously I want to have Groovy and Scala and of course Java together. Isn't it natural wish?
Fortunately scala compiler is smart as well and knows how to do joint compilation with Java. Scala does it a bit differently than Groovy - by parsing Java source during Java compilation. So the process looks like following
1) Compile Scala code using Java sources on the way
2) Compile Java sources using already compiled scala classes
Unfortunally (but not surprisingly) scala has no clue about Groovy.
Today I realized that the small modification of my original algorythm + scala compiler can create joint compiler for all three languages together. The complete algorithm is following
1) Generate Java stubs from Groovy sources
2) Compile Scala code using Java sources and generated stubs on the way
3) Compile all Java code with generated stubs and compiled Scala classes
4) Compile Groovy code with already compiled Java classes
I believe you will not be surprised that when I knew what I want to do it was pretty easy to implement. In fact it was mostly refactoring of what we did before. So now in my working copy I can compile Groovy+Java+Scala together. Of course all references in all three languages are resolved correctly in all possible direction.
I think it opens many amazing opportunities of Groovy becoming orchestration language for people who needs both static and dynamic typing plus functional programming. Of course I would like to see it as part of Groovy Core.
I would like to learn what other people think about it. Please let me know.
Also if we decide to go forward with it I will need help from some ANT expert to incorporate such change in to groovy ant tasks. Any volonteers?
Alex
Free Forum — Powered by Nabble