• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can you integrate Dart easily into existing projects?

 
Ranch Hand
Posts: 125
1
Clojure Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 16
5
Google Web Toolkit Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Michael Swierczek
Ranch Hand
Posts: 125
1
Clojure Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
ice is for people that are not already cool. Chill with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic