Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT vs typescript [closed]

Tags:

typescript

gwt

There are a number of posts on GWT vs javascript but I couldn't find any on GWT vs typescript.

I have about 20,000 lines of code in Java I need to move over to the browser client. However, it's not just recompile in GWT if I go that route. There's a bunch of objects referenced in that code that I need to remove (the existing code is part of a much larger program).

In addition, some low-level classes that are widely used are changing. It's not a big change but these classes are used in a lot of places. So it's really a rewrite either way. A bit smoother rewrite if I got to GWT, but a rewrite nonetheless.

This code also has no GUI or I/O component. It's called by javascript on the client and is used solely to process the javascript objects created and used by the javascript code.

Which leads to my question. What are the advantages and disadvantages of GWT vs typescript?

like image 316
David Thielen Avatar asked Oct 01 '22 20:10

David Thielen


2 Answers

Well if I correctly understand you, you want to run Java code that was previously run on the Server/Java Applet in the browser without GUI.

I haven't used Typescript so I will highlight the advantages of GWT (maybe some of them also apply to Typescript):

  • You having existing Java code, so GWT is a naturally fit (with Typescript you have to rewrite everything).
  • You can use super-source to override classes and packages that won't work in the Browser. This is huge because you will end up with more or less one code base that's capable of running on Browsers, Servers, Java Apps, etc. For example the new google drive spreadsheet (web-app, Android app, etc) is built using this technique.
  • GWT supports tree-shaking and thus the cost you play is only for what you really use
  • Advantages (refactoring, type checks) due to static types

The biggest advantage is that most of your code, can be tested in "plain Java". Only those classes that need emulation have to be tested in the browser. You can use SuperDevMode and SourceMaps to debug them directly in the browser.

The recently held GWT.create conference highlighted also some interesting future improvements to GWT. There are plans to optimize the compiler so that it produces javascript code that is optimized for the javascript engines (object layout, etc).
There are also some ideas to use typed arrays which would benefit performance, especially for computational intense tasks.

Possibly GWT could target asm.js which could give you native like performance.

like image 196
Ümit Avatar answered Oct 13 '22 10:10

Ümit


If you and your developers are more comfortable in Java, then GWT is probably the better option. Also, that allows you to at reuse at least some of your existing Java code without changes, whereas if you port to TypeScript, you'll have to rewrite it all.

Unfortunately, I don't know much about GWT, but can offer the following selling points of TypeScript:

  • It is a superset of JavaScript; which means it is easier to get devs up to speed on it who are familiar with JavaScript (assuming they have some experience with static typing).
  • The tooling is pretty good, even in non MS environments. I use WebStorm and Grunt to dev and build; the autocompletion in WebStorm is pretty good.
  • It incorporates "Arrow functions" from the ES6 proposal which reduces opportunities for "this" binding errors in the code.
  • Even without sourcemaps, the code is pretty easy to debug in modern browsers, because the JS source doesn't change very much from the TypeScript source (minus the types, that is.). The sourcemap debugging in chrome is pretty good, though, and I hardly ever debug the JS directly.
  • If you don't want to deal with static typing, you can just mark a variable as :any (or omit the type) and you are effectively back in carefree JavaScript (some people would view the ease with which one can ignore the type system like this as a disadvantage).

Here are some disadvantages of TypeScript that I have observed:

  • The compiler is slowish (though I understand it has been getting faster, its still a few seconds to build most non-trivial projects).
  • The non-MS IDEs, while decent as I mention above, could be better; WebStorm is ok, but some tools like refactoring (for example, renaming a function) don't always work well.
  • The various forms of module imports can be a pain to deal with, but this is mostly a legacy issue with Javascript not having a standard import format.
like image 32
mushin Avatar answered Oct 13 '22 12:10

mushin