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

 

raspberry pi books

 

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


JetBrains AI Assistant - A Welcome Time Saver
28/02/2024

JetBrains AI Assistant saves developers up to eight hours per week and they appreciate its help.  77% of users feel more productive, 75% express that they are happier with their IDE experien [ ... ]



We Built A Software Engineer
20/03/2024

One of the most worrying things about being a programmer today is the threat from AI. It has gone so far that NVIDA CEO Jensen Huang proclaims that you really shouldn't start training as a programmer  [ ... ]


More News


Last Updated ( Tuesday, 31 January 2012 )