📜 ⬆️ ⬇️

Language Dart - Structured web programming

image

Dart is a new class-oriented language for creating structured web applications. It is designed to be simple, efficient and scalable. Dart combines powerful new features with familiar language constructs in one clear and readable syntax.

Main features


Classes

Classes and interfaces are a simple and clear mechanism for creating various APIs. These constructs add encapsulation and reuse of methods and data.
')
Optional Types

Dart programmers can add static types for their needs. Depending on the programmer and on the development workflow, the code can migrate from a simple non-typed prototype to a complex modular application with strong typing. Typed code allows you to write less documentation to explain what is happening in the code, and type checking tools can be used for debugging.

Libraries

Developers can create and use libraries that are guaranteed not to change at runtime.

Instruments

In addition to the language itself, Dart includes a rich set of runtimes, libraries, and tools for developing and supporting the language. These tools allow you to efficiently develop and debug your code, including editing the code during debugging.

Language objectives


Now Dart is at the very beginning of its development. The following goals will guide the language in its development:
- Create a structured and at the same time flexible programming language for the web
- Make Dart familiar and natural to programmers
- Make it so that all language constructs provide high performance and quick start to the application
- Make it possible to run Dart on all sorts of web devices, including phones, tablets, computers and servers.
- Provide tools that allow Dart to run on all major modern browsers.

These goals solve the following problems that web developers often encounter:
- Small squeaks very often mutate into huge applications without any structure, they are very difficult to debug and problematic to maintain. In addition, these monolithic applications cannot be divided into adequate parts, so different development teams cannot work on them separately. Web applications cannot be productively developed when they become too large.
“Script languages ​​are popular because their lightweight structure allows you to quickly write code. As a rule, arrangements between parts of the application are transmitted in the form of comments, instead of using language structures. As a result, other developers find it difficult to understand, read, and maintain such code.
- Existing languages ​​divide developers into 2 camps: adherents of static and dynamic languages. Traditional static languages ​​require heavy tools and complex coding styles that restrict the developer.
- Developers cannot create homogeneous systems that span both client and server, with the exception of a few classes for Node.js and Google Web Toolkit (GWT).
- Different languages ​​and formats entail a context switch, which complicates the coding process.

Show me the code


Here are some examples that give an idea of ​​the language as a whole.

Classes and Interfaces

Dart interfaces and classes enable you to create extensible blocks that can be reused. An interface defines a basic set of methods and constants that can also inherit from other interfaces. A class can implement several interfaces, but it can inherit only from one superclass.

The following example defines an interface, along with a class and a superclass that implement this interface:
interface Shape {
  num perimeter();
}

class Rectangle implements Shape {
  final num height, width; 
  Rectangle(num this.height, num this.width);  // Compact constructor syntax.
  num perimeter() => 2*height + 2*width;       // Short function syntax.
}

class Square extends Rectangle {
  Square(num size) : super(size, size);
}


Dart . . , .

, , Dart, Point, x y scale() distance().
class Point {
  var x, y;
  Point(this.x, this.y);
  scale(factor) => new Point(x*factor, y*factor);
  distance() => Math.sqrt(x*x + y*y);
}

main() {
  var a = new Point(2,3).scale(10);
  print(a.distance());
}

, . , x, y factor num Point num:
class Point {
  num x, y;
  Point(num this.x, num this.y);
  Point scale(num factor) => new Point(x*factor, y*factor);
  num distance() => Math.sqrt(x*x + y*y);
}

void main() {
  Point a = new Point(2,3).scale(10);
  print(a.distance());
}

Dart?


Dart :
— Dart JavaScript : Chrome, Safari 5+, Firefox 4+ ( ).
— Dart
— Dartboard Dart .

MIME


Dart HTML #import #source . MIME Dart — “application/dart”:
<html>
  <body>
    <script type="application/dart">
      main() {
        Element element = document.getElementById('message');
        element.innerHTML = 'Hello from Dart';
      }     
    </script>
    <div id="message"></div>
  </body>
</html>


Dart - :
Core Library
.
DOM Library
HTML5 DOM, HTML5 W3C/WHATWG. HTML5.

Core Library ( ):
image


. , , -. Dart:
— dartlang.org , , Dart
— Google Code code.google.com/p/dart
— Google Groups groups.google.com/a/dartlang.org/group/misc

Creative Commons Attribution 3.0 License, BSD License

Source: https://habr.com/ru/post/130064/


All Articles