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

 

blog comments powered by Disqus

 

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


ScratchJr - Teaching Kids To Code With iPad
04/08/2014

A new version of the Scratch programming language for use on the iPad has been designed to help teach young kids, who may not yet have learned to read, to create programs using a touchscreen interface [ ... ]



Goodbye Google Maps API for Flash
14/08/2014

The, already deprecated, Google Maps API for Flash will be finally switched off on September 2nd. So if you haven't already migrated to the JavaScript version you need to do so pdq (pretty darn quick) [ ... ]


More News


Last Updated ( Tuesday, 31 January 2012 )
 
 

   
RSS feed of news items only
I Programmer News
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.