3 ms·
If you can't run standard JLS semantics, there's little point to writing the code in Java in the first place. I'm an old user of GWT and hopeful for its reviva
by stickfigure 11y ago
If you can't run standard JLS semantics, there's little point to writing the code in Java in the first place.
I'm an old user of GWT and hopeful for its revival, but I strongly disagree with this statement. There are two ways of going about this - one is to hew closer to Java semantics (the GWT approach), the other is to hew closer to Javascript semantics. Strict JLS semantics is great for bulk compiling huge projects, but sucks for interop. In the new GWT, does Long become a javascript number? In the old GWT it was an opaque object, which was a constant irritant when interacting with JS.
There is room for both approaches, but as a web developer, I need to interop with JS frameworks more than I need to compile Quake.
- cromwellian 11y agoDo you need java.lang.Object and java.lang.String to work properly? Do you need Java interfaces and 'instanceof' to even work? We're not talking about 100% JLS semantics, but if you can't even compile code that utilizes java.lang.* and java.util.*, why not just use Kotlin, Dart, Typescript, and other languages provide high level typed JS like languages. Using a language that doesn't compile properly leads to all kinds of nasty surprises and hard to diagnose bugs.
- skybrian 11y agoEmulation is a matter of degree. There are certainly many places where GWT takes a shortcut or doesn't support a feature compared to a real Java VM. But the idea is to get it right for most of the code a Java developer is likely to write, so you have a chance of writing portable code and getting it to work everywhere without a wholesale rewrite. In particular, mapping Java longs to doubles doesn't make sense. If it's your own code, why are you using long instead of int (or double) which perform much better and interoperate well with JavaScript? If it's someone else's code, how do you know it doesn't need the full 64-bit range?
- stickfigure 11y agoIt makes a ton of sense when working with identifiers, which is so common that it's almost the standard usage of java.util.Long. In most practical applications you can safely assume that identifiers are not going to use the full 64 bit range. And being able to pass them to javascript frameworks is incredibly useful - which is to say, the inability to use them in JS was incredibly frustrating with GWT.
- cromwellian 11y agoGWT 2.8 already does this. Long are passed as doubles unless they exceed 2^32. Also, Double and Boolean are now unboxed native values. And Object[] can be transparently passed to JS and back. Moreover, varargs work between JS and Java, maintaining the semantics of both sides to work correctly. If you want to build true hybrid apps that combine Java and JS programs, there's a lot more considerations that have to be made, we learned some hard lessons the last 3 years on Inbox, which is why JsInterop was redesigned 3 times to get the semantics sound.