Google Helps Devs Convert JavaScript To Dart
Written by Ian Elliot   
Tuesday, 31 January 2012

Google has realized that as most programmers know JavaScript, one good way to get them to use Dart is to provide a guide for the JavaScript programmer.

How do you get programmers to switch language?

The most obvious way is to make sure that the new language is so good that you would be an idiot not to use it. Failing this simple strategy, you can also attempt to lower the barrier to moving to the new language.

Dart is Google's proposed replacement for JavaScript and in its basic form it takes a program written in Dart and converts it to JavaScript so that it can run in any browser. Now Google has realized that, as most programmers know JavaScript, one good way to get them to use Dart is to provide a guide for the JavaScript programmer.

JavaScript to Dart Synonym is a website that lists common JavaScript idioms and how these translate to Dart.

 

jstodart

 

 

To quote Aaron Wheeler on the Google Code blog:

We started with the basics that every JavaScript and jQuery developer knows: variables, arrays, functions, classes, DOM manipulation, and many more. Then, with the help of the Dart team, we recorded the corresponding Dart versions of each idiom. To practice what we learned, we wrote this app with Dart.

The problem with a lexicon of this sort is that it varies from the trivial and the obvious though to the very subtle. For example, the fairly obvious:

JavaScript:

var numbers = [42, 2.1, 5, 0.1, 391];
numbers.sort(function(a, b) {
  return a - b;
});

Dart

var numbers = [42, 2.1, 5, 0.1, 391];
numbers.sort((a, b) => a - b);

the very subtle:

JavaScript

function Person() {
  this.name = null;
};

Person.prototype.greet = function() {
  return 'Hello, ' + this.name;
}

Dart

class Person {
  var name;
  greet() => 'Hello, $name';
}

If you know any JavaScript, you will know that this covers up a huge range of options in how you create a class. This is no syntactic change.

 

googledart

 

And to an extent this is the problem. If new language just involves a syntactic change then it is almost sure to be a worthless swap. To get any real advantage there have to be some semantic changes which cannot be expressed simply as an "instead of writing this" type rule. To make use of a new language you have to think different or the language isn't worth the effort.

So thanks to Google for the effort, but it is going to take something more than this to get Dart to the number one slot.

More Information 

Translating JavaScript to Dart

Related Articles

Google starts to detail Dart

Google spawns yet another language - Dart

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter, Linkedin or Facebook or sign up for our weekly newsletter.

Banner


Microsoft Releases Dev Proxy 0.21
08/10/2024

Microsoft has released an update to Dev Proxy, its command-line API simulator. The updated version, v0.21, adds the ability to simulate authentication and authorization using API keys and OAuth2 among [ ... ]



Spring One 2024 Sessions Now Available Online
04/10/2024

The sessions from this year's SpringOne conference covering everything and anything concerned with the Spring framework are accessible online for free.


More News


Last Updated ( Tuesday, 31 January 2012 )