4 ms·
I understand why these types of compilers lack reflection support, but it still bothers me (and general makes me want to avoid them). JavaScript is naturally a
by jsight 12y ago
I understand why these types of compilers lack reflection support, but it still bothers me (and general makes me want to avoid them). JavaScript is naturally a very dynamic environment, and both Java and Scala have some pretty strong dynamic capabilities of their own.
But somehow when they are combined (GWT or Scala.js) you end up with something that is more static than Java or JavaScript. I know the reasons have to do with the static compilation optimization, but I still think this is a huge downside relative to languages that are designed for the browser from the start.
- noelwelsh 12y agoReflection is very much the last option when using Scala, as it breaks the ability to statically reason about code.
- densh 12y agoIn Scala one can perform reflection purely at compile-time using macros [1]. This lets you to generate code that would have required reflection in other languages with a much better performance. For example pickling [2] library uses macros to statically generate highly efficient serialisation and deserialisation boilerplate. [1] http://docs.scala-lang.org/overviews/macros/overview.html http://docs.scala-lang.org/overviews/macros/overview.html [2] http://lampwww.epfl.ch/~hmiller/pickling/ http://lampwww.epfl.ch/~hmiller/pickling/
- adrusi 12y agoI don't understand why compilers can't simply emit global variables containing structural descriptions of types. It seems like such a trivial thing to do. It would increase the size of the binary, but it would be possible to disable in projects that aren't using reflection, even automatically if the code never imports the reflection package. Maybe someone can explain this.
- sjrd 12y agoOh yes, compilers could do that. But because of the code explosion, everyone would actively stay away from that feature. And we, compiler writers, don't want to support a feature that's not used.
- tlarkworthy 12y agoa Scala Manifest? http://www.scala-lang.org/api/current/index.html#scala.reflect.Manifest http://www.scala-lang.org/api/current/index.html#scala.refle...
- Gurkenmaster 12y agoCeylon does this when compiling to JS because it has to support reified generics both on the jvm and in the browser. I don't like the size of the model though. It's huge.