This page is no longer maintained — Please continue to the home page at www.scala-lang.org

automated conversion of Scala source code to Java

9 replies
Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
I read somewhere on the Scala site (but I can't seem to find it at the moment) that a project is in the works to develop an automated conversion of Scala source code to Java. Does anyone know when that is expected to be available? Also, does anyone know if the readability of  the resulting Java code is expected to be comparable to the readability of the Scala code? Thanks.

--Russ

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: automated conversion of Scala source code to Java
I think the project wasa Java --> Scala translator, no the other way around.

In any case, you can see a Java-ish version of your code by passing the -print option to scalac

--j

On Thu, Feb 12, 2009 at 4:02 PM, Russ Paielli <russ.paielli@gmail.com> wrote:
I read somewhere on the Scala site (but I can't seem to find it at the moment) that a project is in the works to develop an automated conversion of Scala source code to Java. Does anyone know when that is expected to be available? Also, does anyone know if the readability of  the resulting Java code is expected to be comparable to the readability of the Scala code? Thanks.

--Russ


Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: automated conversion of Scala source code to Java
I found it:

http://www.scala-lang.org/node/291

On Thu, Feb 12, 2009 at 4:33 PM, Jorge Ortiz <jorge.ortiz@gmail.com> wrote:
I think the project wasa Java --> Scala translator, no the other way around.

In any case, you can see a Java-ish version of your code by passing the -print option to scalac

--j

On Thu, Feb 12, 2009 at 4:02 PM, Russ Paielli <russ.paielli@gmail.com> wrote:
I read somewhere on the Scala site (but I can't seem to find it at the moment) that a project is in the works to develop an automated conversion of Scala source code to Java. Does anyone know when that is expected to be available? Also, does anyone know if the readability of  the resulting Java code is expected to be comparable to the readability of the Scala code? Thanks.

--Russ





--
http://RussP.us
Detering Dirk
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
RE: automated conversion of Scala source code to Java

Hi Russ,

> Also, does anyone know if the readability of the resulting
> Java code is expected to be comparable to the readability of the Scala

> code? Thanks.

ironic {
Yes, it would be comparable, with the result being: much lesser
}

serious {
Just for my curiosity:

What would be the criteria to say that the Java code
is equally readable to the Scala code?
Or: At which point would you consider it
}

KR
Det

Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: automated conversion of Scala source code to Java
I asked that question only because I have seen automated language converters (e.g., Fortran to C) that produce gobbledygook. The resulting C code may be equivalent to the original Fortran code, but it is a mess, and it is nowhere near as readable by a human. I wasn't trying to make any kind of statement about the relative readability of Scala vs. Java.

On Fri, Feb 13, 2009 at 1:16 AM, Detering Dirk <Dirk.Detering@bitmarck.de> wrote:
Hi Russ,

> Also, does anyone know if the readability of  the resulting
> Java code is expected to be comparable to the readability of the Scala

> code? Thanks.

ironic {
 Yes, it would be comparable, with the result being: much lesser
}

serious {
 Just for my curiosity:

 What would be the criteria to say that the Java code
 is equally readable to the Scala code?
 Or: At which point would you consider it
}


KR
Det



--
http://RussP.us
Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: automated conversion of Scala source code to Java

The problem is that Java is already gobbledegook, so anything
targetting it already starts on a bad footing. In particular, a lazy
val, a function (not a method), a method within a method, anything
involving covariance and contravariance annotations [+T], [-T], more
than one parameter list, case classes, type parameters that are
primitive types in Java, symbolic method names, inline blocks ( val x
= { val y = 5; y * y } ), structural types, pattern matching, implicit
conversions, implicit values, imports from objects, by-name parameters
and inferred types will translate to shitty Java, because Java is
awful at expressing the kind of code that benefits from these
features.

But other than that..

2009/2/13 Russ Paielli :
> I asked that question only because I have seen automated language converters
> (e.g., Fortran to C) that produce gobbledygook. The resulting C code may be
> equivalent to the original Fortran code, but it is a mess, and it is nowhere
> near as readable by a human. I wasn't trying to make any kind of statement
> about the relative readability of Scala vs. Java.
>
> On Fri, Feb 13, 2009 at 1:16 AM, Detering Dirk
> wrote:
>>
>> Hi Russ,
>>
>> > Also, does anyone know if the readability of the resulting
>> > Java code is expected to be comparable to the readability of the Scala
>>
>> > code? Thanks.
>>
>> ironic {
>> Yes, it would be comparable, with the result being: much lesser
>> }
>>
>> serious {
>> Just for my curiosity:
>>
>> What would be the criteria to say that the Java code
>> is equally readable to the Scala code?
>> Or: At which point would you consider it
>> }
>>
>>
>> KR
>> Det
>
>
>
> --
> http://RussP.us
>

Ben Hutchison 2
Joined: 2009-02-14,
User offline. Last seen 42 years 45 weeks ago.
Re: automated conversion of Scala source code to Java

Russ Paielli wrote:
> I read somewhere on the Scala site (but I can't seem to find it at the
> moment) that a project is in the works to develop an automated conversion of
> Scala source code to Java. Does anyone know when that is expected to be
> available? Also, does anyone know if the readability of the resulting Java
> code is expected to be comparable to the readability of the Scala code?
>
Hi Russ,

Thanks for the heads-up. I could use this emitter myself (I'd be
prepared to accept poor Java source readability).

Based on the revision log view, it seems like Lex Spoon was the main
committer on that project, and the last commit is 6 months ago. Does
anyone know if the java src emitter can still support Scala 2.7.3 or 2.8?

https://lampsvn.epfl.ch/trac/scala/log/scala/branches/jvm-src/src

-Ben

Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: automated conversion of Scala source code to Java
I was just thinking that some customers who are not yet ready for Scala might accept Java. The Scala->Java converter would, in theory, allow developers to write in Scala for those customers. But clean, readable Java code would be required. Judging by Mr. Clarkson's earlier post on this thread, that does not seem likely, unless perhaps the Scala features are restricted to those that translate well to Java (a restriction that would effectively neuter Scala).

I am wondering what your application is that does not need readable Java source code.

--Russ


On Tue, Feb 17, 2009 at 10:03 PM, Ben Hutchison <benh@ibsglobalweb.com> wrote:
Russ Paielli wrote:
I read somewhere on the Scala site (but I can't seem to find it at the
moment) that a project is in the works to develop an automated conversion of
Scala source code to Java. Does anyone know when that is expected to be
available? Also, does anyone know if the readability of  the resulting Java
code is expected to be comparable to the readability of the Scala code?
 
Hi Russ,

Thanks for the heads-up. I could use this emitter myself (I'd be prepared to accept poor Java source readability).

Based on the revision log view, it seems like Lex Spoon was the main committer on that project, and the last commit is 6 months ago. Does anyone know if the java src emitter can still support Scala 2.7.3 or 2.8?

https://lampsvn.epfl.ch/trac/scala/log/scala/branches/jvm-src/src

-Ben

Ben Hutchison 2
Joined: 2009-02-14,
User offline. Last seen 42 years 45 weeks ago.
Re: automated conversion of Scala source code to Java

Russ Paielli wrote:
> I was just thinking that some customers who are not yet ready for Scala
> might accept Java. The Scala->Java converter would, in theory, allow
> developers to write in Scala for those customers.
>
I agree with Ricky on this one. Mapping Scala to Java wont be at all
pretty, although undoubtedly educational!

> I am wondering what your application is that does not need readable Java
> source code.
>
There's two things I had in mind:

1. Compiling for CDLC to target J2ME (ie mobile devices) for game
development [http://playscapegames.com]

Although Scala had a now apparently unmaintained CDLC target, I would
much prefer to go via Java source, so I can run, maintain, support and
debug the code using standard Eclipse tools. I read Java source much
better than bytecode, and the transform from src to CDLC bytecode is
already stable and well proven.

Naturally, to run on CDLC (in typically limited mobile-device memory)
would require avoiding some Scala features and most library calls (eg
structural types are reportedly v. difficult without reflection) but one
might still get a big boost over plain Java.

2. As a pathway to other environments, eg to C#/.NET/XNA using Sharpen,
or to Javascript via GWT, maybe even to iPhone somehow.

[http://developer.db4o.com/blogs/product_news/archive/2008/05/20/smart-java-to-c-conversion-for-the-masses-with-sharpen.aspx]

Although Scalac has ability to emit .NET, and previously CDLC, you have
to ask "am I willing to trust and support an opaque bytecode generator
that I don't understand, and almost no one else is using?". With
intermediate Java code, my comfort level goes right up.

-Ben

DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: automated conversion of Scala source code to Java
On Wed, Feb 18, 2009 at 6:34 AM, Russ Paielli <russ.paielli@gmail.com> wrote:
I was just thinking that some customers who are not yet ready for Scala might accept Java. The Scala->Java converter would, in theory, allow developers to write in Scala for those customers. But clean, readable Java code would be required. Judging by Mr. Clarkson's earlier post on this thread, that does not seem likely, unless perhaps the Scala features are restricted to those that translate well to Java (a restriction that would effectively neuter Scala).

I'll tell you now: If you use pattern matching in any non-trivial way, it ain't translating to nice Java. :-)

At least, not until I'm a lot further along with my efforts on it...

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland