Wish for Dart: low cost of transition from (and back to) Javascript

57 views
Skip to first unread message

rob brown

unread,
Oct 13, 2011, 4:55:27 PM10/13/11
to mi...@dartlang.org
What would sell me on Dart is if it could talk to Javascript easily (without jumping through hoops), and allow easy transitioning from one to the other easily.

It's my opinion that if you want Dart to have a chance of succeeding outside of the walls of Google, you need to eliminate the pain of switching from JS.  Otherwise I believe it is as futile as trying to move people from Facebook to Google+ -- you will never reach the critical mass to make it worth it for most people to switch.

A few specifics:

1) whereever you can, make it possible to share code between Dart and JS developers.  If I can post some code, say on my blog or  Stackoverflow, that runs in either language, you will not have split the dev community in two.  Sure it may only be possible on the function level, but that is ok.  Any decisions about syntax should take into account keeping it identical to JS where possible.

2) put a lot of effort into having it produce beautiful, human readable JS as output (including comments).  This helps with the code sharing thing, as well as giving early adopters some insurance against Dart NOT taking off, they can switch back to JS without it hurting so badly.

3) make it perfectly easy to call JS code from Dart code, and vice versa, without ugliness.  It should be at least as easy as it is to integrate legacy C with C++ (or Objective C).  I understand there are some fundamental differences between the languages, but I think you can build a nice bridge between them that hides -- as much as possible -- any messiness.

4) I'd like to be able to do object literals in the same way as JS, i.e.
  var o = {x: 5, y: 3};
  var sum = o.x + o.y;

 as opposed to having to do something more like:

  var o = {"x": 5, "y": 3};
  var sum = o["x"] + o["y"];

Sure, I can do the second one, but the first not only seems "prettier" (and less typing) to me, but (more importantly) it allows me to port over working JS code without having to change a ton of stuff.

5) I'd like to be able to communicate from one module to another (on the same page) easily.  There are lots of powerful things you can do with bookmarklets, plug ins, various debug tools, etc if you can communicate freely, without the restrictions Dart has about crossing script tags.  Maybe developers should have to be explicit about it, so by default you don't have as much potential for clashes.  But something, otherwise you are taking away a lot of cool things you can do in JS.  Feel free to have some kind of flag that prevents doing this, so you can block external scripts from "crossing into your space".  But if people have a reason they might want to do this, and you block them from doing it, you have given them a very good reason to reject Dart outright.

6) eval() (and the like) is very powerful in some cases.  Especially debug tools and the like.  Just because it can be used stupidly doesn't mean there is no place for it.  Same as with #5, feel free to have a flag that disallows this, but don't give people one more reason to say "I can't use Dart because it prevents me from doing something useful I can do in JS".

7) make any Dart libraries run in Javascript as well (or reproduce them in Javascript).  If you want to have it share the closure library, that is fine, but make sure any Dart additions get folded back into the JS version.

8) Ok, this isn't a "better integration with JS" thing, because JS doesn't do this as I'd like, but I'll say it anyway.... I really want some sort of Heredoc syntax, where I can mix in larger chunks of html and other strings into my code (where they will be assigned to Dart string variables), without having to escape everything in horrible ways.  Preferably done in a way that syntax hiliters in editors can easily handle it  (as they can handle mixed together blocks of  php/html and html/js/css in a single file)

-r

John Tamplin

unread,
Oct 13, 2011, 5:35:11 PM10/13/11
to r...@karmatics.com, mi...@dartlang.org
On Thu, Oct 13, 2011 at 4:55 PM, rob brown <rjb...@gmail.com> wrote:
8) Ok, this isn't a "better integration with JS" thing, because JS doesn't do this as I'd like, but I'll say it anyway.... I really want some sort of Heredoc syntax, where I can mix in larger chunks of html and other strings into my code (where they will be assigned to Dart string variables), without having to escape everything in horrible ways.  Preferably done in a way that syntax hiliters in editors can easily handle it  (as they can handle mixed together blocks of  php/html and html/js/css in a single file)

String html = @'''
<div>
<a href="foo">Don't worry about quotes</a>
</div>''';

As far as tools knowing that this string should be formatted as HTML vs some string formatted as SQL vs some other string left as normal, I don't know that there is a good solution here without making too much work for something that happens too infrequently.

--
John A. Tamplin
Software Engineer (GWT), Google

rob

unread,
Oct 13, 2011, 5:46:04 PM10/13/11
to General Dart Discussion
Ahh that's nice to see that you can do it. Yeah I don't know how you
can hint to editors what what language a string is in, but at least
for html I would expect it to be a common case that an editor would
want to handle. Regardless, I'm glad to see the langage has that
feature, it is a major omission from javascript, in my opinion.

On Oct 13, 2:35 pm, John Tamplin <j...@google.com> wrote:

Ladislav Thon

unread,
Oct 13, 2011, 6:07:40 PM10/13/11
to John Tamplin, mi...@dartlang.org, r...@karmatics.com

> As far as tools knowing that this string should be formatted as HTML vs some string formatted as SQL vs some other string left as normal

Leave it to the IDEs, IntelliJ IDEA can already handle this :-)

Zexx

unread,
Oct 14, 2011, 4:37:11 AM10/14/11
to General Dart Discussion
Comparison to Facebook and Google+ is really good. Obviously Google+
is much better organized, more intuitive and with more potential than
Facebook. Dart seems much better than JS. But the problem is in semi-
illiterate users (Facebook) and simple script programmers (JavaScript)
who have very low standards. They don't see the difference since they
never needed anything more advanced.

Charles Forsyth

unread,
Oct 14, 2011, 8:36:27 AM10/14/11
to Zexx, General Dart Discussion
On 14 October 2011 09:37, Zexx <zex...@gmail.com> wrote:
> They don't see the difference since they
> never needed anything more advanced.

... since they *think* they never needed anything more advanced.

rob

unread,
Oct 14, 2011, 2:28:49 PM10/14/11
to General Dart Discussion
On Oct 14, 1:37 am, Zexx <zex2...@gmail.com> wrote:
> Comparison to Facebook and Google+ is really good.

I'm glad you liked my comparison, but really I think the difference
between Google+ and Facebook is that, if I go onto Facebook, I see a
whole lot of people posting pics and articles and conversing and
whatnot.

If I go onto Google+, I see half a dozen early-adopter types, who have
posted one or two messages along the lines of "HELLO? IS THIS THING
ON!" (and then they've gone back to Facebook)

Critical mass counts for *everything*. Javascript has critical
mass....you can find libraries, examples, people to help you, etc....a
huge community of people and code. The only way for Dart to get this
is if they are pragmatic, and assume that developers will want to dip
a toe or two in the water before diving in completely. To do that,
Google needs to make it as Javascript compatible as possible, rather
than splitting the community of web coders.

-r
Reply all
Reply to author
Forward
0 new messages