"Easy language. Flying" ten-minute getting started tutorial (Revision 1, update for ef1.1.0)

Source: Internet
Author: User
"Easy language. Flying" 10 minutes getting started tutorial

(Revision 1, update for ef1.1.0)

 

Author: liigo, 2007.8.12

Address: http://blog.csdn.net/liigo/archive/2007/08/12/1739861.aspx

Reprint must indicate the source: http://blog.csdn.net/liigo/

This article was first launched in 2007.1.1. Now, 1.1.0, the third test version of "easy language. Flying", has been released for nearly two months. This version updates this tutorial.

Dear friend, would you like to spend ten minutes learning a brand new programming language "easy language. Flying" (EF?

  • 1st minutes: overture
  • 2nd minutes: new acquaintance of "easy language. Flying"
  • 3rd minutes: the first program
  • 4th minutes: the First Class Library
  • 5th minutes: Guess digital games
  • 6th minutes: basic syntax
  • 7th minutes: Object-oriented
  • 8th minutes: Special syntax
  • 9th minutes: Answer time
  • 10th minutes: Close

 

1st minutes: overture

It's only 10 minutes. It's time-consuming. Let's get started right away and don't talk much nonsense (isn't it a nonsense? Haha ).

In fact, you don't need to be so nervous. The average reading speed is 300 words per minute, and 10 minutes is enough to read 3000 words. Besides, I don't plan to write it that long, because I have to leave enough time for my dear readers to think about it.

As a ten-minute introductory tutorial, this article cannot cover all aspects. It can only focus on the content that beginners focus on, care about, or are interested in. The main purpose of this article is to give readers a general understanding and perceptual knowledge of "easy language. Flying" in a short time. If you want to get deeper, more detailed, more authoritative, more organized, more logical (or more abstract, more rigid ?) Please read the "easy language. Flying" White Paper officially provided by the easy language-This book is well written! This article provides a lot of reference to this White Paper.

(In this article, I occasionally referred to "easy language. Flying" as EF, and EF as its English name .)

 

2nd minutes: new acquaintance of "easy language. Flying"

First, let's look at EF in a few simple sentences:

  • Fully object-oriented, with a complete concept of classes and interfaces (forget structured programming from now on)
  • It has an automatic garbage collection mechanism (you just need to create an object, instead of releasing it yourself, it's much easier)
  • The source code will be compiled into a local machine code, and the program has a high execution efficiency (of course, it is not as efficient as the C language)
  • The same set of source code can be compiled into executable files under multiple operating systems (Windows/Linux/...). This is a cross-platform mechanism.
  • The source code can be compiled into easy language class libraries for code reuse. In addition, you can use C/C ++ to develop an easy-to-use "local class library ". The development class library is very easy.
  • There is a "system" Class Library (similar to the "core support library" in the original easy language) to provide the core support for the program, is necessary for the program to run, its file size is less than 300 kb, small and exquisite.
  • There is a cross-platform graphical user interface (GUI) Class Library Based on wxWidgets, which is not yet mature.
  • At present, all kinds of class libraries are very lacking, but time will improve everything
  • A complete integrated development environment (IDE), including "Visual Interface Design", is being developed. Most of its code will be compiled in easy language. (For the time being, use a text editor to write a program. Oh, we recommend emedit. It provides better support for Chinese Character syntax highlighting)
  • Feiyang easy language has many special syntaxes, such as "friendly names (similar to Natural Language Programming)", "three-way attention style", "multiple return values", "two-way assignment", and "Attribute Table.

I think it is necessary to emphasize again: "easy language. flying flying "is totally different from the original easy language (1.x-4.x). (If you have to find the same points, they are all easy language company products, both authors are Wu Tao-"Father of easy language "). The former requires a lot of advanced programming concepts and is the trend of future development. The latter has more advantages in programming resources and is a more mature practical product.

 

3rd minutes: the first program
Public class startup class
{
Public static startup ()
{
Console. Output line ("Hello! ");
}
}

Save the above Code as a plain text file hello. EF, note that the encoding format must be UNICODE (such as UTF-8 ).

Compile the command line:

EC hello. ef-ecl_name = "program"-starter_cls = "Startup class"-out_mode = runable -out1_hello.exe

The above command line will compile and generate the hello.exe file. to execute this program, make sure that the EF system library file "system. NCL" is in the current directory.

The execution result of hello.exe is displayed on the screen: Hello!

Remember? The first easy language (old version) program Wu Tao taught us is also "Hello !". The "Hello World" that many people like to write is just a faint greeting, like "hello, Motherland !" So affectionate? China never lacks internationalists, but what we need is nationalism!

(Dear friend, if you only have three minutes, you can go back to work or have a rest now. However, I sincerely invite you to spend seven minutes in your busy schedule to continue reading this article !)

 

4th minutes: the First Class Library

You can compile the source code file of the "first program" as an EF class library without any changes.

Compile the command line:

ec hello.ef -out_mode=ecl -ecl_name="liigo"

"-Out_mode = ECL" indicates compiling the class library (rather than executable files ), -ecl_name = "liigo" specifies the name of the compiled class library (replace "liigo" with your own name, this is the first EF class library compiled by you. It is very memorable ).

Execute the preceding command line to compile the class library file "liigo. ECL (if you have replaced "liigo" with "Zhang San", the generated file is "Zhang San. ECL "). ". ECL" is the fixed Suffix of the EF class library, which means "Ef class library" (EF class library ).

Now you know, writing a class library is as simple as writing a program.

To use the compiled class library, pay attention to two points: 1. "introduce" the class library; 2. Make sure that the Library is located in the directory specified by the system environment variable "ecls_paths.

 

5th minutes: Guess digital games

The "guess number" game is really very, very classic. Through this small game source code, we can not only learn the basic syntax of "easy language. Flying" (definition class, definition class method, definition variable, if, loop, method call ......), We can also fully appreciate the object-oriented programming ideas.

In the next three minutes, our theme is it! 5th minutes, compile it into an executable file (see the following figure for the compilation method) and play the game by yourself. 6th minutes, I will explain the basic EF syntax involved in the file separately. 7th minutes, I will explain the object-oriented ideology.

Public class startup class // 1st rows
{
Publish static startup () // 3rd rows
{
Guess number = create a guess number (); // 5th rows
// Guess number = create a fully automated guess number ();
Guess. Guess (); // 7th rows
}
}

Class guess number
{
Private integer inner number = 66; // todo: select a random number // 13th rows

Public guess ()
{
Loop (guess number () = false) // 17th rows
{
}
}

Private logic guess number ()
{
Console. Output line ("Please guess one number in 1 :");

Integer = get number ();
Console. Output (number );

If (number = Inner number) // 28th rows
{
Console. Output line ("guessed it, congratulations !! ");
Returns true;
}

If (number> Number) // 34th rows
Console. Output line ("too big, come again. ");
Otherwise
Console. Output line ("too small, again. ");

Returns false; // 39th rows
}

Use an extended integer to obtain a number ()
{
Return to the console. Enter an integer ();
}

}

Class automatic guess number <base class = guess number> // 49th rows
{
Integer current number = 0;

Use an extended integer to obtain a number ()
{
Current number +; // 55th rows
Returns the current number;
}
}

Compile method: Save the above Code as the "Guess number. EF" file (encoded as a UTF-8), and then execute the following command line:
EC guess number. ef-ecl_name = "program"-starter_cls = "Startup class"-out_mode = runable -outdigit guess number .exe

6th minutes: basic syntax

Row 3 defines the class. "public" and "class" are keywords (note: "public", "extended", "private", and "static" are called attributes in the White Paper, in fact, it is equivalent to the keyword, which is not clearly distinguished below); "//" is the beginning of the comment until the end of the line (another form of multi-line comment is "/*... */")

Row 3 defines the class member method "Start ()", which means equivalent to "Main ()" in C/C ++ or Java, or "Main ()" in C ()"

Row 3 defines the variable "Guess" of the type "guess number" and creates an object of the type "guess number, assign the created object to the variable "Guess" (that is, the variable "Guess" references this object)

In row 3, the member method "Guess ()" of the "Guess" (strictly speaking, the "variable" refers to the object referenced by the "Guess") is called ()"

Row 3 defines a "private" class member variable with the data type as an integer "inner number" and specifies the initial value as 66.

Line 3: "loop" statement. If the condition in parentheses ("guess number ()" returns "false") is true, the code in curly brackets is cyclically executed, the cycle ends when the conditions in the parentheses are invalid. "Loop" is equivalent to "while" in C/C ++/Java/C"

In the second row, if the statement is used to determine whether the values of the two variables "Number" and "inner number" are equal, the code in the brackets is executed.

If the value of the variable "Number" is greater than the value of "preset number" in the "if-otherwise" statement. If the value is greater than the value of the variable "Number", 34th rows are executed. Otherwise, 35th rows are executed.

Line 3: "return" Statement, end this method, and return the corresponding value (here "false ")

In row 3, define a class "automatic digit prediction" and specify its "base class" as "digit prediction"

In row 3, the value of the variable "current number" is increased by 1, that is, 1 is added on the basis of the original value.

 

7th minutes: Object-oriented

The real world is composed of all things (objects. In the program, the concept of objects is abstracted to describe and express everything in the real world. This is an object-oriented design concept.

Based on the source code of the previous "guess number", here we will briefly introduce the concepts of "encapsulation", "inheritance", and "polymorphism" in object-oriented systems.

Let's take a look at the "Guess number" class. Its data member "preset number" is "private", and its method member "guess number ()" is also "private", that is, they are invisible to the outside world, that is, they are strictly restricted and can only be used inside the "Guess number" class. Since it cannot be directly operated by code outside the class, this class maintains relatively independent. The member method of "getting numbers ()" is "extended", that is, it allows external (subclass) conditional use. Only the member method "Guess ()" is "public" and can be used by the outside world at will. Through the "private" and "extended" and "public" mechanisms, the class not only hides implementation details, but also discloses operation interfaces. This is the concept of "encapsulation.

Let's look at the fully automated guess number class. It does not define the member method of "Guess ()", but the outside world can call its "Guess ()". Why? This is because the base class of "fully automated guess numbers" is "guess numbers", and "Guess ()" is derived from its base class "guess numbers. The concept of "inheritance" in object-oriented systems is similar to that in real life, children inherit the property of their fathers. Subclass can only inherit "public" and "extended" members of the base class, but not "private" members.

The concept of "polymorphism" is more complex, harder to understand, and harder to explain. In general, the member method that should be called is determined dynamically based on the actual object type (rather than the variable type) (during program running, rather than during compilation. Polymorphism usually depends on inheritance and overwrite (The subclass defines the member method in the same declaration form as its parent class 'public or extended member method, the method in the subclass will overwrite the method in the base class ).

The following code provides a detailed explanation:

Guess number = create a guess number ();
// Guess number = create a fully automated guess number ();
Guess. Guess ();

Comments the second line to only execute the first line, and comments the first line to only execute the second line. The program has different running results, the main "secret" is the polymorphism mechanism. In this program, the polymorphism mechanism is mainly reflected in the member method of "getting numbers ()"-it is an "extension" method that can be overwritten, it has also been overwritten (the base class "guess number" defines a "get number ()", and the sub-class "Fully Automatic guess number" also defines a "get number ()", the latter overwrites the former ). The program has two running results, that is, because there are two "getting numbers ()" and which "getting numbers ()" is executed, depends on the actual type of the object (determined at creation and never changed): If the object type is "guess number" (the first line), then "guess number. "Getting a number ()" is called. If the object type is "full automatic number guessing" (second line), "full automatic number guessing. "Get number ()" is called. You may still be wondering that these two classes have only one "Guess ()" method, which is defined in the "Guess ()" of the base class "guess number () "Can I call the" get number () "method in the sub-class" fully automated guess number? Yes, because the subclass "get number ()" overwrites the base class "get number ()". This is the essence of polymorphism and the most difficult to understand.

The object-oriented thinking can not be quickly understood and mastered, and requires meticulous taste and long-term practice. Object-oriented is a science. Many people have been learning for a lifetime.

 

8th minutes: Special syntax

Friendly name-- Write a program in a natural language format:

If the following friendly names are defined:

Friendly name: Write <A> to the screen = console. Output line ();

The program can be written as follows:

'Write 123 to the screen ';
'Write "easy language" to the screen ';
'Write <x> to the screen '(x = 100.123 );

Triplicate:

You can write "If (0 <x <10)" without having to do anything like C/C ++, Java, C # It must be written as "If (x> 0 & x <10 )". "0 <x <10" is the most common way of writing in mathematics. Naturally, why is it not supported by other programming languages? I think that all programmers learn mathematics before learning programming. At the beginning, this strange "x> 0 & x <10" is inevitable, but the design masters of various programming languages turned a blind eye to this!

Multiple return values:

Define a method with multiple return values:

Text, integer name and age ()
{
Return ("China", 5000 );
}

Call the preceding method to receive multiple return values:

Text name; integer age;
(Name, age) = name and age ();

Bidirectional value assignment operator"<=>" -- Exchange the values of two variables:

Integer A = 1, B = 2;
A <=> B; // after execution, the value of a is 2, and the value of B is 1;

If there is no bidirectional assignment operator, it is generally written as "c = A; A = B; B = C;" or "A = a + B; B = A-B; A = A-B; "or" A = a ^ B; B = a ^ B; A = a ^ B; ". How troublesome is it.

Version 1.1.0 introduces some very useful syntax features, for example, "traversal loop", "parameter default value/extended parameter", "embedded type/embedded method", "Chinese and English bilingual keywords", and "general type. I have written a special article on "Chinese and English bilingual keywords:Can you tell which programming language is used to write this code?.

 

9th minutes: Answer time

With easy language, why do we need to re-develop "easy language. Flying "?

There is an official answer, please see here: http://www.dotef.cn/faq.html

What are the essential improvements of "easy language. Flying" compared with the original easy language?

Fully object-oriented, automatic garbage collection, self-developed class libraries, seamless integration with C/C ++ and other languages, pure text source code, Unicode support ......

There are already many programming languages. Do we still need a brand new programming language?

When assembly language was born, C language was born, C ++ was born, Pascal was born, Java was born, C # was born, there will be the same question, the answer is one: "Yes ". The same is true for "easy language. Flying.

"What is the interaction with C/C ++ language?

You can use C/C ++ or other languages to develop easy-to-use local class libraries, which are equivalent to libraries developed by the language itself. They can be referenced and complementary.

What are the similarities between "easy language. Flying" and Java?

In terms of syntax, there is an automatic garbage collection mechanism; there is a concept of "reference" and there is no "pointer". Cross platforms are supported; they all have their own class libraries; they support Unicode, multithreading, and class reflection; they all have stuff like "class path", "Java Doc", "JNI ......

Why is it so similar to Java?

I have no idea about the syntax. Both of them copy the C language. In other aspects, it is normal and reasonable to move "easy language. Flying" closer to the most advanced programming concepts.

What is different from Java?

Compiled language, directly executes machine code, and has high running efficiency (Java is interpreted and executed by JVM in combination with JIT); the most elaborate Runtime Environment (runtime environment ); import with "class library" rather than "package" as the unit; there is no strict requirement on the path of the source code file (Java requires that the source file be located in a specific subdirectory, same as package). Only one public class can be written to a single source code file. The class constructor is fixed to "initialization ()", and the Destructor is fixed to "cleaning () (the constructor name of the Java class is the same as the class name, with no destructor); Exception Handling Mechanism is not supported currently; the special syntax mentioned above;

How is the quality and efficiency of the garbage collector (GC?

It has not been tested in practice. According to my personal non-strict test, the garbage collector works normally when 10000 objects are referenced by each other and there are a large number of circular references. The average time for each collection operation is about 20 milliseconds. GC may interrupt program execution during work. The interval between each recycle task is about 6 to 10 seconds, which can be adjusted. The specific garbage collection algorithm is unknown.

How many class libraries are available now?

From the analysis of various aspects, the system. NCL, reflection. NCL, debugging. NCL should be a mature class library. Other class libraries include: user interfaces, tools, regular expressions, encoding conversion, XML ....... The user interface class library seems to be changing all the time, but the "Ef ide" based on such libraries has taken shape (according to EF official blog ).

 

10th minutes: Close

I suddenly realized that the article had been written for a long time. It may have been 20 minutes since you read it? I am sorry for this. But please do not complain, because I spent more than 20 hours in this article!

I hope you will have some gains after reading this article. Thank you for your valuable time. Thank you for your criticism.

I would like to pay tribute to Wu Tao, a senior IT engineer from China, and to his easy language development team!

 

References:

"Easy language. Flying" Official Website: http://www.dotef.cn

"Easy language. Flying" official technical blog: http://blog.csdn.net/efdev/

"Easy language. Flying" White Paper: http://www.dotef.cn/docs/whitebook/

 

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.