Angel \”Java\” Lopez on Blog

October 10, 2011

Dart Programming Language: Javascript killer?

Filed under: Dart, JavaScript, Programming Languages — ajlopez @ 10:48 am

Today was the day. Google new child, Dart programming languages, was unveiled. First, some links:

My previous post: Dart Programming Language: the new kid on the block
The announced Keynote at Goto Conference

Today Lars Bak post
Dart: a language for structured web programming
http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html

Keynote Slides

Official Site
http://www.dartlang.org

The code
http://code.google.com/p/dart/

Hello World
http://www.dartlang.org/docs/getting-started/index.html

Language Specification
http://www.dartlang.org/docs/spec/index.html

Some news:

Google unveils Dart, its new programming language for building web applications
http://thenextweb.com/google/2011/10/10/google-unveils-dart-its-new-programming-language-for-building-web-applications/

Google starts to detail Dart
http://www.i-programmer.info/news/98-languages/3174-google-starts-to-detail-dart.html

Google debuts Dart, a JavaScript alternative
http://news.cnet.com/8301-30685_3-20117924-264/google-debuts-dart-a-javascript-alternative/

Now, some examples and comments. Simple language, this is the hello world:

main() { 
    var name = 'World'; 
    print('Hello, ${name}!');
}

Design goals (from Technical overview)

  • Create a structured yet flexible programming language for the web.
  • Make Dart feel familiar and natural to programmers and thus easy to learn.
  • Ensure that all Dart language constructs allow high performance and fast application startup.
  • Make Dart appropriate for the full range of devices on the web—including phones, tablets, laptops, and servers.
  • Provide tools that make Dart run fast across all major modern browsers.

At first glance, yes, it looks simple, familiar (it’s not Objective-C or APL ;-). The constructs are simple, but includes classes and inheritance. Static data types are optional. Notably, it can be run in two modes. See Lars Bak blog:

Dart code can be executed in two different ways: either on a native virtual machine or on top of a JavaScript engine by using a compiler 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.

Then, according to the Technical overview, problems to attack (web developers):

  • 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.
  • 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.
  • 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.
  • 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).
  • Different languages and formats entail context switches that are cumbersome and add complexity to the coding process.

Nice to see Node.js mentioned. Lars Bok wrote:

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.

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’ve made the language and preliminary tools available as open source on dartlang.org. Check out the site to give feedback, learn more about Dart, and participate in its development.

An example with class, interface, types:

interface Shape {
  num perimeter();
}
class Rectangle implements Shape {
  final num height, width; 
  Rectangle(num this.height, num this.width);  // Compact constructor syntax.
  num perimeter() => 2*height + 2*width;       // Short function syntax.
}
class Square extends Rectangle {
  Square(num size) : super(size, size);
}

Notice the num type: Dart supports int and double as subtypes of num. See the Core Library (subject to change).

I could use the below code in my AjDraw javascript project 😉

class Point {
  var x, y;
  Point(this.x, this.y);
  scale(factor) => new Point(x*factor, y*factor);
  distance() => Math.sqrt(x*x + y*y);
}
main() {
  var a = new Point(2,3).scale(10);
  print(a.distance());
}

See the => notation for function definition. No code at constructors? Yes, you can write it. Notably, there are named constructors:

class Point {
  num x, y;
  Point(this.x, this.y);
  Point.zero() : x = 0, y = 0;
  Point.polar(num theta, num radius) {
    x = Math.cos(theta) * radius;
    y = Math.sin(theta) * radius;
  }
}

More details at Idiomatic Dart: setter, getters in fields, factory constructors, function declaration, use of =>, string interpolation, equality (oh! it has == and ===).

Update: Isolate communication. There is no direct multithreading support in language (I guess the VM supports it). There are port in Isolates:

class Printer extends Isolate {
  main() {
    port.receive((message, replyTo) {
      if (message == null) port.close();
      else print(message);
    });
  }
}
main() {
  new Printer().spawn().then((port) {
    for (var message in ['Hello', 'from', 'other', 'isolate']) {
      port.send(message);  
    }
    port.send(null);
  });
}

First impresions: hmmm… it’s more clear than Javascript, but it could create a live ecosystem? browser adoption? At least, it can be compiled to Javascript. And apparently it’s easy to grasp.

My Links:

http://www.delicious.com/ajlopez/dart

It’s time to write a Dart interpreter in C#, and compile it to C#, leveraging CLR and .NET libraries. It’s DartSharp time! 😉 https://github.com/ajlopez/DartSharp

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

September 10, 2011

Dart Programming Language, the new Kid on the Block

Filed under: Dart, Google, JavaScript, Programming Languages — ajlopez @ 1:52 pm

This week I received a link via Twitter (I don’t remember the source) about a new programming language by Google. As a programming language geek, I was immediately interested in the topic. Yesterday, I found more information at Node.Js group:

[nodejs] Google going to push a new client-side language – Thoughts?

There is a mail

"Future of Javascript" doc from our internal "JavaScript Summit" last week

Executive Summary

Javascript has fundamental flaws that cannot be fixed merely by evolving the language. We’ll adopt a two-pronged strategy for the future of Javascript:

– Harmony (low risk/low reward): continue working in conjunction with TC39 (the EcmaScript standards body) to evolve Javascript

– Dash (high risk/high reward): Develop a new language (called Dash) that aims to maintain the dynamic nature of Javascript but have a better performance profile and be amenable to tooling for large projects. Push for Dash to become an open standard and be adopted by other browsers. Developers using Dash tooling will be able to use a cross-compiler to target Javascript for browsers that do not support Dash natively.

That’s the 10,000 foot overview…

…The emergence of compelling alternative platforms like iOS has meant that the web platform must compete on its merits, not just its reach. Javascript as it exists today will likely not be a viable solution long-term. Something must change. ..

The “evolve Javascript” option is relatively low risk, but even in the best case it will take years and will be limited by fundamental problems in the language (like the existence of a single Number primitive). Javascript has historical baggage that cannot be solved without a clean break. Thus, although it’s low risk, it’s also relatively low reward.

The “clean break” option is extremely high risk–it will be a huge challenge to convince other browser vendors to rally around a new language–but is the only way to escape the historic problems with Javascript. Thus, its high risk is matched by the potential for a very high reward–a classic leapfrog strategy.

….

The only solution is to execute the two strategies in parallel…

It would be interesting to know what are the “fundamental flaws that cannot be fixed merely by evolving the language”. Javascript has good and bad parts. But most of the bad parts can be skipped. My guess: Google guys points to global variables, maybe a bit convoluted inheritance, no types. But they said Dash new language will be able to be cross-compiled. Yes, types! I read:

Dash: The Clean Break Dash is the leapfrog effort that is designed to be a clean break from Javascript. It will seek to keep the parts that have made the Internet so successful, but fill in holes everyone agrees it has.

Dash is designed with three perspectives in mind:

– Performance — Dash is designed with performance characteristics in mind, so that it is possible to create VMs that do not have the performance problems that all EcmaScript VMs must have.
– Developer Usability — Dash is designed to keep the dynamic, easy-to-get-started, no-compile nature of Javascript that has made the web platform the clear winner for hobbyist developers.
– Ability to be Tooled — Dash is designed to be more easily tooled (e.g. with optional types) for large-scale projects that require code-comprehension features such as refactoring and finding callsites. Dash, however, does not require tooling to be effective–small-scale developers may still be satisfied with a text editor.

Dash is also designed to be securable, where that ability does not seriously conflict with the three main goals.

Dash will be designed to be consumed in a number of locations:

– Browser VM — Our aspiration is that Dash will ultimately be a viable substitute for Javascript as the native client-side language of choice across all browsers.
– Front-end Server — Dash will be designed as a language that can be used server-side for things up to the size of Google-scale Front Ends. This will allow large scale applications to unify on a single language for client and front end code.
– Dash Cross Compiler — Dash will be designed so that a large subset of it can be compiled to target legacy Javascript platforms so teams that commit to using Dash do not have to seriously limit their reach. Platforms that have a Dash VM can operate on the original Dash code without translation and take advantage of the increased performance. One of the ways we will evolve Harmony is to be a better target for such compiled Dash code.

All this could be an April Joke, but not. A new language is coming, and its name is Dart, not Dash.

There is an article:

Google Confirms Hints Dropped About Dart ‘Structured’ VM

Two conferences being held next month, one in Aarhus, Denmark on October 10 and another two weeks later in Portland, Oregon, are scheduled to feature Lars Bak, the designer of the V8 interpreter used in Google Chrome. In Aarhus, Bak will be joined by Gilad Bracha, a Google engineer and co-author of the original Java Language Specification and the creator of the Newspeak programming language, a derivative of Smalltalk.

About Newspeak and Gilad Bracha (who visited my country, Argentina, last year):

http://en.wikipedia.org/wiki/Newspeak_%28programming_language%29

Newspeak is a programming language and platform in the tradition of Smalltalk and Self being developed by a team led by Gilad Bracha. The platform includes an IDE, a GUI library, and standard libraries.[1] Starting in 2006, Cadence Design Systems funded its development and employed the main contributors, but ceased funding in January 2009.[2]

Newspeak is a class based language. Classes may be nested, as in BETA. This is one of the key differences between Newspeak and Smalltalk. All names in Newspeak are late-bound, and are interpreted as message sends, as in Self.

Newspeak is distinguished by its unusual approach to modularity.[3] The language has no global namespace. Top level classes act as module declarations. Module declarations are first class values (i.e., they may be stored in variables, passed as parameters, returned from methods, etc.) and are stateless.

….The name "Newspeak" is inspired by George Orwell‘s newspeak appearing in the novel Nineteen Eighty-Four. The heading on the programming language’s website says "It’s doubleplusgood". The motivation for the name is that Orwell’s Newspeak language grew smaller with every revision; Bracha views this as a desirable goal for a programming language

http://bracha.org/Site/Home.html
http://newspeaklanguage.org/
http://gbracha.blogspot.com/

Twitter @Gilad_Bracha

Bracha’s position about Javascript:

The Truthiness Is Out There

For the past 5 years or so, I (like many others) have argued that Javascript is the assembly language of the internet platform. Over this period, some of the obstacles that limit the applicability of said platform have been slowly pushed aside. Things like client side storage, or decent performance.

However, Javascript remains a seriously limited language for platform implementation. Here are some of the problems…

Another article:

Google announces Dart programming language

Now, Google has already released one language in recent history — Go — so we can assume that Dart won’t be a C-like system-oriented language. With the “structured web programming” moniker, it’s also likely to be some kind of interpreted, in-the-browser language — so more like JavaScript or Python, and less like Java or other compiled languages. One of the biggest hints, though, is that both Bracha and Bak have worked extensively with Smalltalk in the past — and an interpreted Smalltalkesque language would fit right into the “structured web programming” mold, too.

And this is the official keynote, Dart intro into society, October 10th:

Presentation: "Opening Keynote: Dart, a new programming language for structured web programming"

Google to unveil World News at GOTO Aarhus. The whole world will be on alert when Google presents a new programming language "Dart" in the opening keynote speak on conference monday. Join us and GOTO Aarhus and get all the details.

Apparently, there is no published info about syntax, semantic, examples. Dart is a mystery. I started my link collection:

http://www.delicious.com/ajlopez/dart

There is a new programming language under the sun. Smalltalk for the masses? Javascript for ever? Time to port AjScript to AjDart 😉

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Blog at WordPress.com.