aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Can you integrate Dart easily into existing projects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can you integrate Dart easily into existing projects?" Watch "Can you integrate Dart easily into existing projects?" New topic
Author

Can you integrate Dart easily into existing projects?

Michael Swierczek
Ranch Hand

Joined: Oct 07, 2005
Posts: 107
    
    1
Chris Buckett,

Thank you to you and to Manning for participating in the book giveaway, and thanks for taking the time to answer questions.

I guess first and foremost, how easy is it to integrate Dart with existing Javascript and how useful would it be to do that? My situation, which I assume is typical, is that I maintain a Java web application that had most of its original Javascript hand-written, and then later started adding jQuery piecemeal as needed. The application is still evolving, though. Obviously you can't give specific recommendations without a detailed exploration of the project, but could you hazard a guess as to whether Dart would be worthwhile? I did see that part of chapter 12 in your book discusses interacting with Javascript.

Also, functional programming is getting a lot of attention these days. It appears to me that Dart tries to be pretty close to Java and C#, and of course that makes the learning curve shallower for developers comfortable with either of those languages. But do you think Dart might be hurt in the long run for missing some of the features in ClojureScript (a port of the LISP dialect Clojure to Javascript), Scala, etc... ? Or does Dart really support most typical functional programming constructs right out of the box?

Thanks,
-Mike
Chris Buckett
author
Greenhorn

Joined: Feb 12, 2013
Posts: 16
    
    5

Hello!

1. Integrating with existing code.

Dart can interop with existing JavaScript, and vice-versa, but you need to have a mental model of the two worlds being separate. In practice, this is because the Dart VM and the JavaScript VM co-exist in the browser, even when Dart is converted to JavaScript. This means that calling from one to the other is an async operation, with listeners and callbacks on each side of the fence as required.

A good use case for interop with an existing app might be when you want to add a new feature to your app, perhaps distinct from existing code - think something like a live news ticker. Your page might already be receiving news feeds via ajax - you could use that same javascript to pass data over to the Dart app (or perhaps in reverse, use code written in Dart to retrieve the data and pass it over to an existing JavaScript component for display).

(I'm not able to comment directly on ClojureScript, so I'll compare with JavaScript)...
Dart is as functional as JavaScript. By this, I mean that you can write Dart code almost the same as you would write JavaScript, by ignoring the fact that Dart has classes and storing all your object's data and methods in maps, and returning closures to represent private methods, and other "hacks" like that. Dart's funtions are first-class For example, the following is valid Dart:



Part of the design rationale for Dart is that seems familar, and there are a vast number of developers who will feel at home with Dart's imperative model, but enough FP that developers can learn another paradigm if they so wish.

Thanks,
Chris.


Chris.
- my DartWatch blog
Sign up for the - Dart Weekly Newsletter
- Read my book Dart in Action
Michael Swierczek
Ranch Hand

Joined: Oct 07, 2005
Posts: 107
    
    1
Chris Buckett,

Thank you for taking the time to answer my question. I like the functional example you gave, it is relatively easy to understand the syntax and I never read Dart code before.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you integrate Dart easily into existing projects?