Table of contents
When creating a language, programmers sought to make it:
- similar to other programming languages so that Dart can be quickly mastered;
- structured and flexible for fast and easy web development;
- fast - so that applications written in this PL work quickly both in browsers and other environments (for example, on smartphones).
You should look at the basic constructions of the language in order to understand its key features.
Declaring variables. The interpreter needs to be explicitly told that the word at the beginning of the statement is the name of the variable. This is done by inserting VAR. For example, to create a variable i, you need to write the following construction: var I;
Once a variable has been declared, it can be assigned a value. This is already done without using the reserved word: I = 0;
As in C, a semicolon is placed at the end of a Dart statement. It tells the interpreter to jump to the line below.
The output of information in Dart is implemented through the built-in Print function. But, unlike, for example, the same Python, here it works differently. The main difference is that this function works exclusively with strings. That is, for example, in order for the program to print some number, it must first be turned into a string.
Start of the program. It's almost the same here as it is in C. The body starts with a main() declaration. And the following code is placed between curly braces. Example:
Inside parentheses (after main) are the function arguments. Inside the curly ones are the instructions of the program. Be sure to take into account that there can be no instructions outside of curly functions. It is only possible to declare variables and functions there.
Now that you know the basic syntax of the language, you can write a complete program. Let it just add 2 numbers:
var one = 3;
var two = 7;
var sum = one + two;
var sumstring = sum.toString();
The result of the program is the output of the number 10. Let's see how this happened.
As already explained, main() is the declaration of the program, and everything contained in the brackets is its body. Here are the instructions.
The first two lines declare variables and assign values to them. The equal sign is responsible for this.
Next, another variable is declared, which is called sum. It is assigned the value of the sum of the other two - one and two.
The next line declares another variable called sumstring. It is assigned the value of sum.toString(). The first part is the name of the variable. The second one (the one after the dot) is the name of the function. In this case, it is toString(). It converts any variable value to a string. In the case of a written program, the toString() function converts the number 10 from a numerical format to the number 10 into a string (text).
And the last instruction tells the interpreter to print the contents of the sumstring variable to the screen. And if the conversion from a digit to a string had not been performed, it would not have been possible to display messages. It would be a mistake.
Benefits of Dart
Dart programming has several advantages. The main ones should be considered.
Documentation accessibility. Since Google is developing an interpreter for Dart, all the features of the language are described in detail. This allows you to quickly get answers to almost any questions that may arise both during the learning process and directly while writing the code.
Dart programming is a promising area that is actively developing. It is a powerful and functional language in which it is convenient to write code.