<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Angel "Java" Lopez : Javascript, Dart</title><link>http://msmvps.com/blogs/lopez/archive/tags/Javascript/Dart/default.aspx</link><description>Tags: Javascript, Dart</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Dart Programming Language: el matador de Javascript?</title><link>http://msmvps.com/blogs/lopez/archive/2011/10/11/dart_2D00_programming_2D00_language_2D00_javascript_2D00_killer.aspx</link><pubDate>Tue, 11 Oct 2011 09:38:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1801037</guid><dc:creator>lopez</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/lopez/rsscomments.aspx?PostID=1801037</wfw:commentRss><comments>http://msmvps.com/blogs/lopez/archive/2011/10/11/dart_2D00_programming_2D00_language_2D00_javascript_2D00_killer.aspx#comments</comments><description>&lt;p&gt;Ayer, lunes, fue el día: Google corrió el velo y presentó en sociedad a su nuevo “hijo”: el lenguaje de programación Dart. Primero, algunos enlaces:&lt;/p&gt;  &lt;p&gt;Mi anterior post: &lt;a href="http://ajlopez.wordpress.com/2011/09/10/dart-programming-language-the-new-kid-on-the-block/"&gt;Dart Programming Language: the new kid on the block&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://gotocon.com/aarhus-2011/presentation/Opening%20Keynote:%20Dart,%20a%20new%20programming%20language%20for%20structured%20web%20programming"&gt;La Keynote de anuncio&lt;/a&gt; en la &lt;a href="http://gotocon.com"&gt;Goto Conference&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;El post de ayer de Lars Bak    &lt;br /&gt;Dart: a language for structured web programming     &lt;br /&gt;&lt;a href="http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html"&gt;http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vean la interesante presentación (historia, motivación para Dart, enlaces, relación con otros lenguajes y JVM): &lt;a href="http://gotocon.com/dl/goto-aarhus-2011/slides/GiladBracha_and_LarsBak_OpeningKeynoteDartANewProgrammingLanguageForStructuredWebProgramming.pdf" target="_blank"&gt;Presentación&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;El sitio oficial    &lt;br /&gt;&lt;a href="http://www.dartlang.org"&gt;http://www.dartlang.org&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;El código del proyecto   &lt;br /&gt;&lt;a title="http://code.google.com/p/dart/" href="http://code.google.com/p/dart/"&gt;http://code.google.com/p/dart/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Clásico ejemplo: Hello World    &lt;br /&gt;&lt;a href="http://www.dartlang.org/docs/getting-started/index.html"&gt;http://www.dartlang.org/docs/getting-started/index.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Especificación del lenguaje    &lt;br /&gt;&lt;a href="http://www.dartlang.org/docs/spec/index.html"&gt;http://www.dartlang.org/docs/spec/index.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/language/grammar/Dart.g" target="_blank"&gt;Gramática de Dart&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Algunas noticias:&lt;/p&gt;  &lt;p&gt;Google unveils Dart, its new programming language for building web applications    &lt;br /&gt;&lt;a href="http://thenextweb.com/google/2011/10/10/google-unveils-dart-its-new-programming-language-for-building-web-applications/"&gt;http://thenextweb.com/google/2011/10/10/google-unveils-dart-its-new-programming-language-for-building-web-applications/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Google starts to detail Dart    &lt;br /&gt;&lt;a href="http://www.i-programmer.info/news/98-languages/3174-google-starts-to-detail-dart.html"&gt;http://www.i-programmer.info/news/98-languages/3174-google-starts-to-detail-dart.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Google debuts Dart, a JavaScript alternative    &lt;br /&gt;&lt;a href="http://news.cnet.com/8301-30685_3-20117924-264/google-debuts-dart-a-javascript-alternative/"&gt;http://news.cnet.com/8301-30685_3-20117924-264/google-debuts-dart-a-javascript-alternative/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Bien, veamos algunos ejemplos, con comentarios cortos. El lenguaje parece simple, entendible. Vean el “Hello, World”:&lt;/p&gt;  &lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,courier,monospace;font-size:12px;"&gt;main() { 
    var name = &amp;#39;World&amp;#39;; 
    print(&amp;#39;Hello, ${name}!&amp;#39;);
} &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Los objetivos de diseño (tomados de &lt;a href="http://www.dartlang.org/docs/technical-overview/index.html"&gt;Technical overview&lt;/a&gt;)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Create a &lt;b&gt;structured yet flexible&lt;/b&gt; programming language for the web. &lt;/li&gt;

  &lt;li&gt;Make Dart feel &lt;b&gt;familiar and natural&lt;/b&gt; to programmers and thus easy to learn. &lt;/li&gt;

  &lt;li&gt;Ensure that all Dart language constructs allow &lt;b&gt;high performance&lt;/b&gt; and &lt;b&gt;fast application startup&lt;/b&gt;. &lt;/li&gt;

  &lt;li&gt;Make Dart appropriate for the &lt;b&gt;full range of devices on the web&lt;/b&gt;—including phones, tablets, laptops, and servers. &lt;/li&gt;

  &lt;li&gt;Provide tools that make Dart run fast &lt;b&gt;across all major modern browsers&lt;/b&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A primera vista, sí, es simple, familiar (no es Objective-C ni APL ;-). Incluye clases y herencia. Tipos de datos son opcionales. Notablemente, puede ejecutarse de dos formas: en una máquina virtual nativa para Dart o traducido a Javascript. Leo en &lt;a href="http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html"&gt;Lars Bak blog&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Dart code can be executed in two different ways: either on a native &lt;a href="http://en.wikipedia.org/wiki/Virtual_machine"&gt;virtual machine&lt;/a&gt; or on top of a JavaScript engine by using a &lt;a href="http://en.wikipedia.org/wiki/Compiler"&gt;compiler&lt;/a&gt; that translates Dart code to JavaScript. This means you can write a web application in Dart and have it compiled and run on any modern browser. The Dart VM is not currently integrated in Chrome but we plan to explore this option.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Según &lt;a href="http://www.dartlang.org/docs/technical-overview/index.html"&gt;the Technical overview&lt;/a&gt;, los problemas a atacar (para desarrolladores web):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Small scripts often evolve into large web applications with no apparent structure—they’re hard to debug and difficult to maintain. In addition, these monolithic apps can’t be split up so that different teams can work on them independently. It’s difficult to be productive when a web application gets large. &lt;/li&gt;

  &lt;li&gt;Scripting languages are popular because their lightweight nature makes it easy to write code quickly. Generally, the contracts with other parts of an application are conveyed in comments rather than in the language structure itself. As a result, it’s difficult for someone other than the author to read and maintain a particular piece of code. &lt;/li&gt;

  &lt;li&gt;With existing languages, the developer is forced to make a choice between static and dynamic languages. Traditional static languages require heavyweight toolchains and a coding style that can feel inflexible and overly constrained. &lt;/li&gt;

  &lt;li&gt;Developers have not been able to create homogeneous systems that encompass both client and server, except for a few cases such as Node.js and Google Web Toolkit (GWT). &lt;/li&gt;

  &lt;li&gt;Different languages and formats entail context switches that are cumbersome and add complexity to the coding process. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bien que mencionen a Node.js. Lars Bok &lt;a href="http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html"&gt;escribe&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Dart targets a wide range of development scenarios: from a one-person project without much structure to a large-scale project needing formal types in the code to state programmer intent. To support this wide range of projects, Dart has optional types; this means you can start coding without types and add them later as needed. We believe Dart will be great for writing large web applications.&lt;/p&gt;

  &lt;p&gt;…&lt;/p&gt;

  &lt;p&gt;The language comes with a set of basic libraries and tools for checking, compiling, and running Dart code, all of which will evolve further with your participation. We&amp;#39;ve made the language and preliminary tools available as open source on &lt;a href="http://dartlang.org"&gt;dartlang.org&lt;/a&gt;. Check out the site to give feedback, learn more about Dart, and participate in its development.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Un ejemplo con clase, interfaz, tipos:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,courier,monospace;font-size:12px;"&gt;&lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; Shape {
  num perimeter();
}
&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Rectangle implements Shape {
  final num height, width; 
  Rectangle(num &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.height, num &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.width);  &lt;span style="color:#008000;"&gt;// Compact constructor syntax.&lt;/span&gt;
  num perimeter() =&amp;gt; 2*height + 2*width;       &lt;span style="color:#008000;"&gt;// Short function syntax.&lt;/span&gt;
}
&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Square extends Rectangle {
  Square(num size) : super(size, size);
}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Noten el tipo num: Dart soporta int y double como subtipos de num. Vean la &lt;a href="http://www.dartlang.org/docs/technical-overview/images/interface-hierarchy.png" target="_blank"&gt;Core Library (subject to change)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Podría usar el código de abajo en mi proyecto javascript &lt;a href="https://github.com/ajlopez/AjDrawJs" target="_blank"&gt;AjDraw&lt;/a&gt; ;-)&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,courier,monospace;font-size:12px;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Point {
  var x, y;
  Point(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.x, &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.y);
  scale(factor) =&amp;gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Point(x*factor, y*factor);
  distance() =&amp;gt; Math.sqrt(x*x + y*y);
}
main() {
  var a = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Point(2,3).scale(10);
  print(a.distance());
}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Vean la notación =&amp;gt; para las funciones (también pueden definirlas normalmente). ¿No hay código en los constructores? Sí, lo hay, pueden escrirlo. Pero en el ejemplo de arriba se ve la notación para asociar los parámetros recibidos con las variables del objeto. Notablemente, hay constructores con nombre:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,courier,monospace;font-size:12px;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Point {
  num x, y;
  Point(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.x, &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.y);
  Point.zero() : x = 0, y = 0;
  Point.polar(num theta, num radius) {
    x = Math.cos(theta) * radius;
    y = Math.sin(theta) * radius;
  }
}
&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Más detalles en &lt;a href="http://www.dartlang.org/articles/idiomatic-dart/" target="_blank"&gt;Idiomatic Dart&lt;/a&gt;: vean setter, getters y campos, constructores factoría, declaración de funciones, el uso de =&amp;gt;, interpolación de string (todos se copian de AjSharp ;-), igualdad (hmm, tienen == y ===).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Veo que tiene comunicación con Isolate, que permite escribir código que se ejecuta en paralelo. Pero no hay soporte DIRECTO de threads (es decir, no se puede lanzar un thread, la máquina virtual los maneja internamente). Vean el uso de port:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,courier,monospace;font-size:12px;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Printer extends Isolate {
  main() {
    port.receive((message, replyTo) {
      &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (message == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;) port.close();
      &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; print(message);
    });
  }
}
main() {
  &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Printer().spawn().then((port) {
    &lt;span style="color:#0000ff;"&gt;for&lt;/span&gt; (var message &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; [&amp;#39;Hello&amp;#39;, &amp;#39;from&amp;#39;, &amp;#39;other&amp;#39;, &amp;#39;isolate&amp;#39;]) {
      port.send(message);  
    }
    port.send(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);
  });
}
&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Primeras impresiones: hmmm... es más claro que Javascript, pero habrá que ver si gana en momento, si se forma un ecosistema activo. Parece que está preparado para ejecutarse en varios browsers. Al menos puede compilarse a javascript, para ejecutarse en donde se acepte javascript. Y al parecer, es fácil de entender.&lt;/p&gt;

&lt;p&gt;Mis enlaces: 
  &lt;br /&gt;&lt;a href="http://www.delicious.com/ajlopez/dart"&gt;http://www.delicious.com/ajlopez/dart&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Es tiempo de escribir un intérprete/VM de Dart en C#, y compilarlo a C#, aprovechando CLR y las librerías .NET (me gustaría que accediera a esas librerías, como ahora hace AjSharp). ¿Será tiempo de un DartSharp? ;-) &lt;a title="https://github.com/ajlopez/DartSharp" href="https://github.com/ajlopez/DartSharp"&gt;https://github.com/ajlopez/DartSharp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nos leemos!&lt;/p&gt;

&lt;p&gt;Angel “Java” Lopez 
  &lt;br /&gt;&lt;a href="http://www.ajlopez.com"&gt;http://www.ajlopez.com&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://twitter.com/ajlopez"&gt;http://twitter.com/ajlopez&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1801037" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/lopez/archive/tags/Lenguajes+de+Programaci_26002300_243_3B00_n/default.aspx">Lenguajes de Programaci&amp;#243;n</category><category domain="http://msmvps.com/blogs/lopez/archive/tags/Desarrollo+Web/default.aspx">Desarrollo Web</category><category domain="http://msmvps.com/blogs/lopez/archive/tags/Javascript/default.aspx">Javascript</category><category domain="http://msmvps.com/blogs/lopez/archive/tags/Dart/default.aspx">Dart</category></item></channel></rss>