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


Random Gifts For Programmers
24/11/2024

Not really random. Not even pseudo random, more stuff that caught my attention and that I, for one, would like to be given. And, yes, if I'm not given them, I'd probably buy some for myself.



AWS Releases Lambda SnapStart For .NET Functions
10/12/2024

Amazon has released new services for AWS Lambda SnapStart,  Amazon's performance optimization that aims to significantly improve the startup time for applications.


More News


Last Updated ( Tuesday, 31 January 2012 )