简体   繁体   English

JS转Dart转换

[英]JS to Dart Conversion

This is a 2 part question. 这是一个2部分的问题。 I am not lazy, simply not fundamentally fluent enough in JS to convert an entire library while referencing the Dart Synonyms page it seems. 我并不是懒惰,只是在JS中没有从根本上说得足够流畅,可以在引用Dart Synonyms页面的同时转换整个库。 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. Dart:js文档解释了如何访问JS全局对象,如本片段所示,但如果我没有弄错,那就不是我想要的了。

Q1: In the example snippet below, it wouldn't increase Angular's performance by utilizing Dart, correct? Q1:在下面的示例代码段中,使用Dart不会增加Angular的性能,对吗?

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中不可用的库, jsparserdart-synonym真的让我感到困惑 - 我找不到任何简单的文档,当我浏览实际的飞镖时,我迷路了。

Dart Editor kicks an error when I try to run and build jsparser : 当我尝试运行并构建jsparser时, Dart编辑器会出错:

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; 未处理的异常:'file:/// C:/ Work Root / Dart / jsparser-ec65c9e7467f / jsparser.dart':格式错误类型:第26行pos 27:未加载类型'选项'列表args = new选项()。参数;

So I tried dart-synonym ; 所以我尝试了dart-synonym ; it ran and built correctly, but then showed a clone of the Dart Synonyms page . 它运行并正确构建,但随后展示了Dart Synonyms页面的克隆。

Q2: If accomplishing an automatic conversion is even possible, how do I use either of these? Q2: 如果甚至可以完成自动转换,我该如何使用其中任何一种?

Dart-synonym does not automatically convert other languages to Dart, it only provides a static synonym reference to allow manual conversion. Dart-synonym不会自动将其他语言转换为Dart,它只提供静态同义词引用以允许手动转换。

jsparser is meant to provide automatic conversion but the last commit is from more than a year ago. jsparser旨在提供自动转换,但最后一次提交是从一年多前开始的。 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. 例如,一段时间后删除了Options类,这就是您收到格式错误的类型错误的原因。

If you want to use Angular in Dart, you can use Google's own port: AngularDart 如果您想在Dart中使用Angular,可以使用Google自己的端口: AngularDart

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-lang ,特别是因为Dart本质上是带有JS语法的Smalltalk,而amber是编译为JS的Smalltalk。 Amber uses two base objects - STObject and JSObject , allowing ST code to call JS code and vice versa. Amber使用两个基础对象--STObjectJSObject ,允许ST代码调用JS代码,反之亦然。 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. 由于amber-lang使用Pharo Smalltalk作为其RI,因此可以使用像SmaCC (Smalltalk解析器构建器)这样的lib来生成包装器解析代码。 It already provides such support for Java, Python, C and a number of other languages. 它已经为Java,Python,C和许多其他语言提供了这样的支持。 The way JS works, you can't write, and certainly not debugm, a large or complex app. JS的工作方式,你无法编写,当然也不能调试大型或复杂的应用程序。 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. Dart尝试按照ST的方式进行,使用强类型系统和语义运行时等效于解释语言,具有接近汇编的速度,但使用JS语法,因为Google有大量的traine node.js程序员。

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). 创建Smalltalk VM比JVM更容易,因为它只包含基础对象,与OS库交互的代码,并且本身用Smalltalk编写并转换为C(或者跨平台库到F-Script) MacOS)使用SLANG(MacOS上的CLANG)。 For that reason IBM Research did a Squeak/Pharo VM that can scale to over 1000 cores (RoarVM on GitHub). 出于这个原因,IBM Research做了一个可以扩展到1000多个核心的Squeak / Pharo VM(GitHub上的RoarVM)。 Doing that with the JVM would probably take a decade. 使用JVM这样做可能需要十年时间。

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. Smalltalk很慢是一个过时的概念(由于不是基于堆栈,不再重要,而且Sun在JIT for Java上做的工作,PoC也在Smalltalk中 - 称为Strongtalk.Pharo的cogit JIT基本上工作同样的方式 - 具有纯解释语义的汇编程序代码。由于MSF4J微服务的速度(缺乏),我不得不离开Java,它本身是Java中最快的,并且比JS中的任何东西都快。我可以运行256个微服务与一个express.js微服务相比,Pharo ST具有更快的启动时间,更少的内存使用,更好的吞吐量和监控/管理。

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. 将32位VM移植到64位UltraSparc非常简单,并且使得能够以比思科产品(在Cisco ASR-9010上运行的IOS程序)更快地过滤和路由大量监控数据的软件。 The Sun/Oracle T5220's go used for about 1/600th the price of the ASR, which is a signicant advantage. Sun / Oracle T5220的使用价格约为ASR的1/600,这是一个显着的优势。

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. 喜欢 Dart,但我必须在某种程度上对我说,这只是YAPL,因为它没有做任何与PHaro和amber-lang相结合的事情。 And the Smalltalk syntax (Ruby is similar) is both more readable and less verbose than JS (or Java for that matter). Smalltalk语法(Ruby类似)比JS(或Java)更具可读性和冗长性。 GO had some good ideas, but not enough to really generate much interest. GO有一些好主意,但还不足以引起很大兴趣。 ST has had 36 years of development, nothing brand new is going to offer equivalent tools or equivalent runtime stability. ST已经有36年的发展历史,没有什么全新的东西可以提供相同的工具或等效的运行时稳定性。

Check out a4bp for an example of data analysis and visualization in Pharo. 查看a4bp ,了解Pharo中的数据分析和可视化示例。 The website is also written in Pharo using Graphviz from within Smalltalk. 该网站也是使用Smalltalk内的Graphviz在Pharo中编写的。 SmallTalkHub is a combination of Pharo ST and amber-lang. SmallTalkHub是Pharo ST和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. Amber-lang可以用来包装像Angular这样的库,直到它变得很容易为任意语言编写浏览器插件,我们不会被JS困住。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM