Monday, 18 June 2012

Start Darting...(Contd.)

Back again! :)
The first part of "Start Darting" is at the following link: (or)

Well, to start afresh and get started, no place is as great as
The steps given below are more detailed in the aforementioned link. Please do go through them. :)
Step 1: Download the dart editor. Its nearly 110MB .zip file, available for Windows, Linux and Mac.
Step 2: Launch the editor by double clicking the executable.
Step 3: Running a dart code.
We saw in the previous post a Hello World sample. The same sample can be run.
If your code has web app, it will launch it in Dartium (Chromium with the Dart VM).

  • New Features about Dart:
      • Snapshots: Modern browsers need to parse a web app’s source code before that app can run. Snapshots here mean that the state and the code is recorded at certain point of time, which will increase the speed at startup.
      • Isolates: These are the processes without any overhead. Each isolate has its own memory and code, which can’t be affected by any other isolate. The only way an isolate can communicate with another isolate is by way of messages. Isolates allow a single app to use multi-core computers effectively. Another use for isolates is running code from different origins in the same page, without compromising security.
      • Interfaces with default implementations: Dart interface can have a default implementation—a class (usually private) that is the default way to create objects that implement the interface.
      • Easy Generics: Dart takes a new approach by designing a generics system that’s more understandable.
      • Optional typing: Its optional to use type in Dart and it won't change the way your app executes, but they can help developers and programming tools to understand your code. You might not bother with types while you’re developing a prototype, but you might add types when you’re ready to commit to an implementation. An emerging pattern is to add types to interfaces and method signatures,and omit types inside methods.
      • HTML library: We also took a fresh look at how you should use the HTML DOM. DOM is short for Document Object Model; it’s the interface that lets you pro-grammatically update the content, structure, and style of a web page.) By creating a native Dart library (dart:html) to access and manipulate the DOM. There are elements, attributes, and nodes to work with.
Un-boxing Dart:
Dart is more of a platform than a language. It has

    • Libraries: The core libraries are like math, server side, I/O, JSON.
    • Virtual Machine: Dart Virtual Machine is used, being run on the browsers as embedded or on the command line.
    • Compiler to java script: The Frog compiler is used to compile the Dart code to java script.
    • Language Specifications: The language looks very familiar like Java or java script because Google wanted mass adoption of the language. If it was a standing new language, only few people would have adopted it. Since, it looks very familiar, people feel comfortable with the optional typing and also isolates.
    • Dart Editor: Its an editor that helps to build complete end to end app. It helps with syntax highlighting, auto completion and running the code.
  • Compiling dart code to java script:
    • The Frog Compiler which come with the SDK, compiles a given Dart code to java script, this could be on the client side. A future version of Chrome will ship with an embedded Dart VM, allowing your Dart code to run directly in Chrome without first being compiled to Java Script.
  • Libraries to play with:
    • dart:core This is the basic library used in majority of the scripts.
        • print() -> display basic text
        • Collection, Set, List, Queue -> group objects in collections
        • Map -> manipulate key-value pairs
        • Date, TimeZone, Duration, Stopwatch -> specify dates and times
        • String, Pattern, RegExp -> use strings
        • num, int, double, Math -> use numbers
        • Future -> return a value before your operation is complete
        • Comparable -> compare similar objects
        • Iterable -> perform an operation on each item in a multi-item object
    • dart:io This library is used on the server side to connect with the outside world.
        • InputStream and OutputStream : Reading and writing data
        • Files and directories : Open and close files
        • Sockets: Connection to the network
    • dart:html: API's for producing UI for webapps.
        • Document and window: get global objects
        • Element query and queryAll: find HTML elements
        • Elements On property: add or remove events
        • Collection Interfaces to operate on group of objects
There exists many more libraries and all you can see when you download the editor and play with it.
Happy Learning! :)

No comments:

Post a Comment