Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

In order to implement all the Scala language magic the generated byte code is sometimes far away from what the equivalent Java code byte code would look like.

This isn't a problem for most people but it is an issue for anyone who uses stuff like byte code instrumentation - take a look at this issue for example: https://github.com/puniverse/quasar/issues/45

It's not a criticism of Scala (the language is just a LOT richer so has to cater for more sophistication).

But the difference matters to me which is why I prefer Kotlin over Scala and I'm prepared to miss out on some of that sweet Scala magic.



sort by: page size:

That is different than the fragile bytecode problem scala appears to have though. Go's issue is that the API's are changing fast so source code has to be modified frequently.

Scala's issue seems to be that even when the API's haven't changed and there is no need for a sourcecode change a compiler change could break you.

Frankly go's problem seems more manageable.


Try to use Scala from Java to see how those bytecodes look like.

It is another layer exactly because you need to translate back those bytecodes into Scala semantics when debugging, when everyone wraps Java libraries into Scala idiomatic wrappers.

I was referring to Kotlin regarding JetBrains.


> Scala needs to add a runtime when compiling to bytecode

Last time I checked you needed like 500kb of libraries for any scala program compiled to Android. Kotlin is a few kb. Kotlin is a small addition to the java API, Scala needs much more things.

> it is not fully compatible with java as kotlin.

As far as I know, the way scala treats types and functions make it that sometimes you cannot call scala code from java. Well, you can most times but requieres a lot of wrappers. This doesn't happen in kotlin.

I learn scala few years ago, my memory is weak and things may change. But I wanted to use it for android and give up quite quickly because of lot of issues. For kotlin was like love at first sight. No problems at all.


The bytecode is the same but not the standard library of classes. Scala uses different collection classes, Option instead of Optional, companion objects instead of static classes, etc...

In my experience mixing scala and java in a single codebase is inelegant, with plenty of conversion code at the boundaries.


It's also a real pain to call Scala code from Java, which makes blending Java and Scala code in a project, or adding Scala code to an existing Java project, much less attractive.

>> An attribute of Scala is that the Scala compiler generates fragile byte-code.

Can anybody tell me if this would be true to any JVM targeted language, or is it a specific issue of the Scala compiler?

I'm asking because I just recently decided to abort learning Scala in favor of Clojure.


Unfortunately it doesn't. Even though Scala and Java output the same kind of bytecode, these languages have different language specifications. We currently only support what's in the JLS.

Yes that is a weakness. My project for work is scala/java and it is not a good experience once Scala gets involved.

I've been hoping that the scala guys tackle this issue soon:

https://github.com/scalameta/metals-feature-requests/issues/...


Scala is a fine backend language, with far more bells-and-whistles than Java 8.

However the comparison beyond language features is very much relevant, including the lack of Android support in Scala 2.12

Adding to the woes, the code emitted by 2.12 is slower ( https://news.ycombinator.com/item?id=12066653 )

Not to say things can't improve. After the initial announcement of 2.12 at ScalaDays 2015 and 2016, expect more at ScalaDays 2017.


Scala compiles down to JVM bytecode. Java also compiles down to JVM bytecode. Scala does not compile down to Java.

> Scala needs to add a runtime when compiling to bytecode

This is nonsense? It doesn't need any more "runtime" than Kotlin does.

> it is not fully compatible with java as kotlin.

This is a lie. (I don't say this lightly, but I've seen it too often from too many kotlin advocates for it to be an innocent mistake)


That makes sense. Library compatibility is a tough issue to deal with. Scala.js faces the same issue when it comes to libraries that depend on the Java stdlib. I believe their goal is to port the entire stdlib, but I'm not sure tbh. It might just be an insurmountable problem.

I find this extremely weird.

Why even use Scala then? Is it just for the implicits and long build times?


but scala's cousin kotlin doesn't seem to suffer from this a lot... kotlin library-packages don't have kotlin-version to their download link... maybe I'm missing something?

The biggest problem with Scala for me are very cryptic compilation errors with several line long type informations that do not match each other.

The second problem is DDL hell. Too many changes to APIs, binary compatibility, dropped classes from 2.7.x -> 2.8.x -> 2.9.x.

That said I'm very happy with Scala as a language, but they should fix those problems.


> Scala

That means being chained to JVM. That is a big downside for me.


regarding jar size, from http://get-scala.org/2.12 (mentioned in this thread already):

 	                2.9 	2.10 	2.11 	2.12
  Scala library 	9.0 	7.1 	5.7 	5.5
  Scala compiler 	11.5 	14.5 	15.5 	10.1
  ScalaTest (3.0.0) 	        10.5 	10.4 	7.0
data is in Megabyte. Compilation would be interesting, since I have read multiple times that it is slower due to a jvm bug. Only a few days ago for example: https://www.reddit.com/r/programming/comments/5ab948/scala_2...

Note that there is also ongoing work to bring the native compilation to Scala[1].

[1] http://www.scala-native.org/


Yup. Same thing with Spark Framework wrt Apache Spark.

Seems like a curse targeting game-changing projects written in Scala.

next

Legal | privacy