1

This is a 2 part question. I am not lazy, simply not fundamentally fluent enough in JS to convert an entire library while referencing the Dart Synonyms page it seems. The Dart:js documentation explains how to access the JS global object as shown in this snippet, but if i'm not mistaken it's not what i'm looking for.

Q1: In the example snippet below, it wouldn't increase Angular's performance by utilizing Dart, correct?

var angular = context(['angular']);
var myapp = angular.module('myApp', ['ngResource','ngRoute']);

If I'm right, and I do need to convert libraries unavailable in Dart, jsparser and dart-synonym are really stumping me -- I can't find any simple documentation and when I look through the actual darts I get lost.

Dart Editor kicks an error when I try to run and build jsparser:

Unhandled exception: 'file:///C:/Work Root/Dart/jsparser-ec65c9e7467f/jsparser.dart': malformed type: line 26 pos 27: type 'Options' is not loaded List args = new Options().arguments;

So I tried dart-synonym; it ran and built correctly, but then showed a clone of the Dart Synonyms page.

Q2: If accomplishing an automatic conversion is even possible, how do I use either of these?

Taylor Evanson
  • 384
  • 4
  • 16
  • possible duplicate of [Is there a converter of Javascript to Dart?](http://stackoverflow.com/questions/7719629/is-there-a-converter-of-javascript-to-dart) – user7610 Apr 02 '15 at 08:33

2 Answers2

2

Dart-synonym does not automatically convert other languages to Dart, it only provides a static synonym reference to allow manual conversion.

jsparser is meant to provide automatic conversion but the last commit is from more than a year ago. A lot has changed since then, and I doubt it will run without significant tweaks to the source. For instance, the Options class was removed a while back which is why you receive that malformed type error.

If you want to use Angular in Dart, you can use Google's own port: AngularDart

Pixel Elephant
  • 20,649
  • 9
  • 66
  • 83
  • Well shit. :) I gave up, i'm learning Dart and the synonyms weren't as hard as I thought. Sorry for being lazy, thank you! – Taylor Evanson Mar 04 '14 at 21:44
  • What if you don't want to port and maintain huge third-party JS libraries? Is there any way to write "ambient" declarations, or thin "wrappers" around existing JavaScript APIs, so that these can be comfortably consumed (with type-safety and other niceness) from Dart code? – mindplay.dk Mar 10 '14 at 14:15
2

You could use a similar technique to amber-lang, particularly since Dart is essentially Smalltalk with JS syntax, while amber is Smalltalk that compiles to JS. Amber uses two base objects - STObject and JSObject, allowing ST code to call JS code and vice versa. Since amber-lang uses Pharo Smalltalk as its RI, a lib like SmaCC (a Smalltalk parser builder) could be used to generate the wrapper parsing code. It already provides such support for Java, Python, C and a number of other languages. The way JS works, you can't write, and certainly not debugm, a large or complex app. Dart is an attempt to do that the way ST does, with a strong type system and a semantic runtime equivalent to an interpreted language, with near-assembler speed, but with JS syntax, since Google has tons of traine node.js programmers on staff.

Creating a Smalltalk VM is much easier than something like the JVM, since it only includes the base Object, the code to interop with OS libs, and is itself written in Smalltalk and converted to C (or the cross platform libs to F-Script on MacOS) using SLANG (CLANG on MacOS). For that reason IBM Research did a Squeak/Pharo VM that can scale to over 1000 cores (RoarVM on GitHub). Doing that with the JVM would probably take a decade.

That Smalltalk is slow is an out of date notion (due to not being stack based, which no longer matters, and the work Sun did on JIT for Java, where the PoC was also in Smalltalk - called Strongtalk. Pharo's cogit JIT works essentially the same way - assembler code with pure interpreted semantics. I had to go away from Java due to the (lack of) speed of MSF4J microservices, which were themselves the fastest available in Java, and faster than anything in JS. I can run 256 microservices in Pharo ST with a quicker startup time, less memory use, better throughput and monitoring / management, than one express.js microservice.

Porting the 32 bit VM to a 64 bit UltraSparc was quite easy, and resulted in software that can filter and route large quantities of monitoring data significantly faster than a Cisco's offering - an IOS program running on a Cisco ASR-9010. The Sun/Oracle T5220's go used for about 1/600th the price of the ASR, which is a signicant advantage.

I like Dart, but I have to say to some degree for me it's just YAPL, since it doesn't do anything not already possible with a combination of PHaro and amber-lang. And the Smalltalk syntax (Ruby is similar) is both more readable and less verbose than JS (or Java for that matter). GO had some good ideas, but not enough to really generate much interest. ST has had 36 years of development, nothing brand new is going to offer equivalent tools or equivalent runtime stability.

Check out a4bp for an example of data analysis and visualization in Pharo. The website is also written in Pharo using Graphviz from within Smalltalk. SmallTalkHub is a combination of Pharo ST and amber-lang. Amber-lang could be used to wrap libs like Angular, until it becomes easy enough to write browser plugins for any arbitrary language and we aren't stuck with JS.