Scala to Java translation

4,924 views
Skip to first unread message

Jan Vanek

unread,
Sep 19, 2013, 11:01:18 AM9/19/13
to scala-user, miguel...@tuhh.de
Hi lucky Scala people,

unfortunately my chef is opposed to Scala and wants me to convert the code which I wrote in Scala to Java. It is approx. 150 files and about 700 kB of code. This is sad, only. I'd like to ask for advice.

As far as I could find on google, Miguel Garcia worked on the Java back-end for Scala in 2010. Miguel, even incomplete translator would be very helpful. What is the state of it? I couldn't find anything here:


Thanks and regards,
Jan

Timo Rantalaiho

unread,
Sep 19, 2013, 1:26:24 PM9/19/13
to Jan Vanek, scala-user

How about compiling the code to Java bytecode and then decompiling to Java?

It would probably be a huge mess, but if you manage to get something compilable out of it, it might be a better starting point than scratch.

Starting from scratch would also be good in the sense that then you would surely have ideas for improvement that are easier to do when starting from a clean slate.

I hope you get bonuses according to SLOC count :)

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michael Shields

unread,
Sep 19, 2013, 1:33:10 PM9/19/13
to scala...@googlegroups.com

Does anyone know a US university professor who is a Scala expert. I’m looking for someone to team with and those are customer requirements.

 

If you do, could you please forward my contact info to them.

 

Thank you,

Mike Shields

336-407-2190

 

Jan Vanek

unread,
Sep 19, 2013, 2:49:49 PM9/19/13
to scala-user
On 19.09.2013 19:26, Timo Rantalaiho wrote:

How about compiling the code to Java bytecode and then decompiling to Java?

It would probably be a huge mess, but if you manage to get something compilable out of it, it might be a better starting point than scratch.


Hi, thanks, that's also what Martijn Hoekstra and Johannes proposed, I'll try that.


Starting from scratch would also be good in the sense that then you would surely have ideas for improvement that are easier to do when starting from a clean slate.


Yes, I considered that, but I realized that first I'm quite happy with code, and second, if I have an idea for improvement, it's easier for me to do the improvement in scala code and do the "rewrite" (sort of monkey rewrite) when I'm satisfied with the scala code.


I hope you get bonuses according to SLOC count :)


LOL. Thanks a lot!

Jan

Miguel Garcia

unread,
Sep 20, 2013, 3:52:33 AM9/20/13
to scala...@googlegroups.com, miguel...@tuhh.de

Jan,

The prototype for Scala to Java translation was intended for compiler hackers. Several features make it unsuitable for production. Its output contain mangled names (which are unreadable, not just because of the dollar signs). Additionally, early initializers can be expressed in bytecode (assigning fields before invoking a superconstructor) but not in Java. I haven't checked recently how many jumps reach the bytecode emitter (again, no problem for bytecode but require reformulation for Java).


Miguel

Dennis Haupt

unread,
Sep 20, 2013, 4:50:17 AM9/20/13
to Miguel Garcia, scala...@googlegroups.com, miguel...@tuhh.de
decompile the scala classes into java source code. you will get an abosolutely unmaintainable mess, but you can keep coding in scala and just convert it all the time and pretend to write java code
WHILE LOOKING FOR ANOTHER JOB :D
 
Gesendet: Freitag, 20. September 2013 um 09:52 Uhr
Von: "Miguel Garcia" <miguel...@tuhh.de>
An: scala...@googlegroups.com
Cc: miguel...@tuhh.de
Betreff: [scala-user] Re: Scala to Java translation
--

Jan Vanek

unread,
Sep 20, 2013, 10:53:53 AM9/20/13
to Miguel Garcia, scala-user
Hi Miguel,

thanks for responding.

I've tested the JAD and JODE decompilers on one of my modules. Both are not satisfying. JODE fails on 50% of class files. JAD converts much more, but it's like a sea of $ characters. There would be a lot of work in renaming, it doesn't seem economical. I'm now looking into Scalariform (thanks to Johannes). It seems like a lower-barrier entry in compare to the compiler. Let's see where this goes. It's good that I only need to convert correct Scala code, and the goal is not a 100% conversion, nor a binary compatibility. I just want to convert as much as possible, so that it looks as good as possible, but it doesn't need to be 100%, it's intended for manual review and fixing.

From your comment about jumps vs. bytecode emitter, Miguel, it would seem that that Java back-end starts a little too late, but I can only guess. The JS backend comes to mind, I think/guess that the Java backend should start as early as JS backend. But it's premature I don't anything about it, just thought that if I fail with Scalariform, I could walk the same path as JS backend.

Regards,
Jan



Simon Ochsenreither

unread,
Sep 21, 2013, 5:20:14 PM9/21/13
to scala...@googlegroups.com, miguel...@tuhh.de
Didn't IntelliJ have this feature? Or was it only Java -> Scala?

Jason Zaugg

unread,
Sep 21, 2013, 5:38:19 PM9/21/13
to Simon Ochsenreither, scala-user, Miguel Garcia
On Sat, Sep 21, 2013 at 11:20 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:
Didn't IntelliJ have this feature? Or was it only Java -> Scala?

No, it's only in one direction.


It might not be *that* tough to build something in the opposite direction, so long as you are just after scaffolding. You could leave certain constructs, like non-trivial pattern matches, untranslated as TODO comments.

-jason

Jan Vanek

unread,
Sep 21, 2013, 5:50:31 PM9/21/13
to scala...@googlegroups.com
Yes, that's also my line of thinking. Especially given the futility of this undertaking.

Thanks for the link.


-jason
Reply all
Reply to author
Forward
0 new messages