What kind of language is dart?

Source: Internet
Author: User

See a piece of news these days-white compatible? Google is preparing a Java-ready Dart application Running framework for Android, without commenting on the headlines and content of the news. But Google's launch of Sky seems to prove that native's development approach to the web more and more close to the trend, the recent comparison of fire to the number of react-native, their principle is similar to the first to construct a virtual DOM tree, Then only the changed DOM is updated. Sky's readme also said that they refer to the react, the biggest difference between the two should be the development of language, react-native is JavaScript, and Google's own pro-son-Dart.

Node node development is now a hot-on-the-roll, unified front-end. Google launched the Dart to unify the front-end development, but these two years have been tepid, as if the domestic use of polymer developers are not many, and now with the sudden announcement of the use of Dart to replace the Android language Java development, but also held the first first session of the Dart De Veloper Summit, it seems that Google is ready to force on DART, I believe that Dart will be at the end of May Google IO Conference on an important issue.
Take advantage of today's holiday, follow the Dart website tutorial to play Dart, find dart This language is really good.

Reference Package

Packages are referenced in the same way as Python and Go import :

import‘dart:html‘;

However, there is a special way to import only one component of a package:

import‘dart:math‘ show Random;import‘dart:convert‘ show JSON;import‘dart:async‘ show Future;
Variable

Dart, like Python, is a strongly typed language that defines a variable without having to specify the type. But Dart also supports specifying variable types.

RandomRandom();String _firstName;String _appellation;

Dart does not have a private keyword, and if the variable or method is a private type, it needs to be preceded by an underscore.

Private variables

class PirateName {  # ...  String _firstName;  String _appellation;  # ...}

Private methods

static _parsePirateNamesFromJSON(String jsonString) {  JSON.decode(jsonString);  names = pirateNames[‘names‘];  appellations = pirateNames[‘appellations‘];}
Type conversions

Dart uses the keyword as to do the type conversion.

void updateBadge(Event e) {  as InputElement).value;}
Method

For some specific methods, Dart provides syntax sugar, which is simple to do. For example, the value of an expression is the case of a return value, which can be written like this:

String toString() => pirateName;

Don't write it like this:

String toString() {  return pirateName;}

If it is a get method, you can directly add a keyword between the return value type and the method name get , and the method name does not require parentheses, and the call does not require parentheses.

StringJSON.encode({"f""a": _appellation});String get pirateName =>    ‘‘‘$_firstName the $_appellation‘;
Cascade operator (.. )

Cascade operator (thecascade operator (..) ) can allow multiple operations to be performed on a member variable.

false         ..text‘Aye! Gimme a name!‘;

The above statement is equivalent to

false;genButton.text‘Aye! Gimme a name!‘;
String conversions

The variable in Dart is much more convenient to string than Java, and Python has a spell, directly preceded by the variable name with the $ symbol.

‘$_firstName the $_appellation‘;
Construction method

Dart supports a name-building approach, which is more advanced than Java and Python.

PirateName.fromJSON(String jsonString) {  JSON.decode(jsonString);  _firstName = storedName[‘f‘];  _appellation = storedName[‘a‘];}

Here PirateName.fromJSON is a whole, with the time to write the whole.

returnnew PirateName.fromJSON(storedName);
Parameters

Like Python, Dart also supports the Optional and Named Arguments, such as the parameters can be written like this:

PirateName({StringString appellation}) {  # ...}

Parameters should be enclosed in curly braces, and the parameters should be encapsulated in a Python-like form Dictionary .

But you don't need to pass all the arguments when you call.

new PirateName(firstName: inputName)
Generic type

Dart supports generics, which is similar to Java, such as defining a List variable that can be written like this:

staticList names = [];staticList appellations = [];

If you want to specify the type, you need to List add the type after the nutshell.

List<StringList<String> appellations = [];

about whether a generic type is supported like Java super , and extend you don't see it, you don't know for a moment.

Asynchronous operation

The Dart language natively supports asynchronous operations, mainly with two keywords await and async .
For example, if we are going to define an async method that does not need to go to the new Threadlike Java, it is OK to add the keyword directly after the method, so that when async the method is called, it returns one directly Future , caller without waiting.

staticasync {  ‘piratenames.json‘;  await HttpRequest.getString(path);  _parsePirateNamesFromJSON(jsonString);    }

awaitLike the wait method usage in Java, it means waiting, but it can only be used async in methods.

For example, in the code snippet above, await HttpRequest.getString(path) it is necessary to wait until the HttpRequest.getString(path) return Future has the final result to continue execution _parsePirateNamesFromJSON(jsonString); .

It is not known that Dart support does not support some high-level language features, such as closures (Closure), lambda expressions (lambda expression), generators (Generator), etc., and looks forward to further learning.

What kind of language is dart?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.