下一個炙手可熱的web UI開發平臺:Dart Platform

再過幾個小時Google 2012 I/O盛會即將開始,Chrome是這次盛會的一個重點(當然還有Android,Cloud,Google Drive,以及沒人用的Google+等等),而在Chrome部分,筆者認爲最大的亮點就是Dart Platform。它必將成爲web ui開發的一個新熱點。





什麼是Dart Platform?

Dart Platform是一個開發複雜web系統的新平臺,Google出品。如果你熟悉GWT(Google Web Toolkit),並且不喜歡直接編寫javascript來開發web UI的話,就會和我一樣,對Dart非常期待。在Dart平臺上,你可以使用Dart語言(對,Dart是一個語言)來編寫代碼,它可以在server端以及現代瀏覽器端(主要是chrome,因爲chrome會集成一個dart的虛擬機)運行。另外,Dart可以編譯成javascript(和GWT類似),因此顯然你編寫的Dart web系統(通過編譯)可以在多種瀏覽器上運行,而不僅限於Chrome。

現在的Dart平臺還處於開發階段,已經發布了Dart語言,Dart庫,一個編輯器(基於Eclipse RCP開發出來的,用慣了Eclipse IDE的人會非常習慣),一個可用於server端和瀏覽器端的虛擬機,以及一個把Dart語言編譯成javascript的編譯器。

Hello World示例:

// Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#library('hi');

#import('dart:html');

main() {
  document.query('#status').innerHTML = 'Hi, Dart';
}


因爲筆者對Dart也是剛剛開始接觸,不敢誇誇其談其語言特性以及前景具體會如何,下面摘抄Google Dart官方給出的Question & Answers中的幾段。

全文在這裏 http://www.dartlang.org/support/faq.html


Q. Is Google planning to put Dart under the control of a standards body?

Yes, we hope to. Once Dart reaches a certain level of maturity and acceptance, we expect that a standards process will be the next step.

Q. What's the future for GWT?

Bruce Johnson posted on the GWT blog (with further comments on Plus): "Dart and GWT both share the goal of enabling structured web programming. In fact, many of the same engineers who brought you GWT are working on Dart. We view Dart as an ambitious evolution of GWT's mission to make web apps better for end users, and we're optimistic about its potential. As Dart evolves and becomes ready for prime time, we anticipate working closely with the GWT developer community to explore Dart."

"Meanwhile, rest assured that GWT will continue to be a productive and reliable way to build the most ambitious web apps—and even games like Angry Birds. Key projects within Google rely on GWT every day, and we plan to continue improving (and open-sourcing) GWT based on their real-world needs."

Q. Isn't Dart a lot like JavaScript?

Yes and no. The Dart project thinks that JavaScript can use some changes for more productive software engineering, smarter editors and development environments, and web apps that are as beautiful and pleasing as the best client apps can be. On the other hand, we don't think everything needs to change, and why change what isn't broken?

Dart, like JavaScript, is a dynamically typed language. It adds optional compile-time type annotations to help you catch errors earlier. It takes out a few features of JavaScript, such as prototypes and the global object: this should streamline the VM, enable faster execution, and make it easier to do code completion and refactoring. And Dart adds some goodies. To name a few:

  • User-defined operator methods. We like the lightweight, readable code these give for our DOM interface.
  • Lightweight syntax for anonymous functions. You use them a lot in web programming; now they look great. And they come with correct binding of this and full block-level lexical scoping, no gotchas.

Dart aims to be like JavaScript, but faster, more regular, and more scalable to large programs.

Q. Isn't Dart a lot like Java?

Well, Java is statically typed, and Dart is dynamically typed. Dart has optional static type annotations, where in Java they are required. To us these are big differences in the nature of the two languages. But Dart is a curly-brace language, and it shares some keywords with Java, such as extends andfinal, so we can see why people make the comparison. Honestly, we like having a straightforward and familiar syntax that's easy to pick up, even if that means it's less exciting.

Q. Can Dart add reflection?

Yes.

Q. Should I write my web app in Dart?

If you want to experiment, we'd love for you to try Dart and give us feedback. If your web app is something that needs to be reliable, we really recommend waiting until Dart is more mature. We've released Dart at a very early stage, and we're likely to make breaking changes to the language.

Q. I have a large JavaScript codebase. How would I migrate it to Dart?

You could use the isolate model described in the previous question, which will encourage you to port fairly coarse chunks with narrow interfaces. We know you might like fine-grained intercalling, but we are nervous that it would have long-term negative effects on the language and on the VM (from experience with GWT JSNI), and we would very much rather do without it. So the native keyword is intended for use only by our core library implementations, because we want to be able to make breaking changes to the interaction between native JavaScript and generated JavaScript, breaking only our own core libraries, not the whole world. Again, we'll see how this works.

Q. What browsers do you plan to support as JavaScript compilation targets?

We're currently aiming to support the following browsers:
  • Internet Explorer, latest two versions that are 9 or higher.
  • Firefox, latest two versions that are 7 or higher.
  • Chrome, latest version.
  • Safari, latest two versions that are 5.1 or higher.
  • Opera, latest version that is 12 or higher.
That's a goal; we don't actually support all of these browsers yet. The goal may change to be either more restrictive or more permissive. We'll refine this further as Dart matures.

Q. What browsers support Dart now?

As of February 2012, no production browsers can execute Dart code unless it's first compiled to JavaScript. However, a Chromium build (nicknamed Dartium) is available that can execute Dart code natively. For details on downloading and using Dartium, see Chromium with the Dart VM.

Q. How do I debug Dart code after it's been compiled to JavaScript?

The generated JavaScript from dart2js is readable, and it's reasonable to use the browser's development tools on it. We expect to eventually provide Source Maps output, which allows you to debug the Dart code from the JavaScript code inside of your browser's developer tools.

Q. Will any valid Dart code compile to JavaScript, or are there limitations?

Yes, we intend for any valid Dart code to compile to JavaScript. If some support is missing from one of our compilers, that's a bug (in either the compiler or the spec).

Q. Does Dart support JSON?

Yes, Dart libraries can parse from and stringify to JSON. You can find such a library atdart/lib/json/.

Q. Will Dart run on the server?

We have some server code now, such as our test suites. Have a look at the file, socket, and process APIs in dart/runtime/bin/.



更新正在進行的Google IO Dart session的一個截屏:



更新最後問答階段的一些內容:

1、dart編譯成js的時候,是針對每個browser編譯一份,還是編譯一份js可以在多種browser上運行?

答:編譯一份js

2、dart editor可否變成Eclipse的plugin,這樣開發者就可以使用Eclipse的種種工具和好處?

答:日期還不能透露,但最終肯定會支持Eclipse plugin的形式

3、什麼是dart成功的標誌?

答:在chrome內置dart虛擬機,完美地支持dart,在google之外的很多項目決定使用dart,dart逐漸被整個web開發社區認可,這就是dart成功的標誌,也是dart team的ultimate goal。

4、dart對server端的支持如何?

答:dart很好地支持json,所以client端和server端可以以json的形式傳輸數據,dart虛擬機也可以在server端運行,dart是一個支持在client端和server端都可以運行的語言。



筆者認爲,google毫無疑問會大力發展和推廣dart,chrome已經決定內置dart虛擬機,現在最大的疑問就是其他主流瀏覽器是否願意直接支持dart,尤其是mozilla firefox,如果dart本身只能在chrome一個瀏覽器上運行,在其他瀏覽器上都必須先編譯成javascript,那它的優越性就大大減弱了(試想一下,dart是一門語言,javascript也是一門語言,對於一個不懂javascript的人來說,學習javascript固然是痛苦的,學習dart再編譯成javascript也沒有吸引力)。相反,如果mozilla也內置dart虛擬機,那dart就會掀起一場web系統開發的革命,瀏覽器的效率將得到革命性的提升!結合cloud技術,未來的終端機真的只要browser+memory就可以了!






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章