Go language learning notes (I) Basics

Source: Internet
Author: User

Before graduation, the ranking of programming languages is a favorite of every month. Pay attention to the few people sitting in the front row, but pay attention to the various languages you have never heard of before. Now I am working. I only occasionally think about it and I will not think too much about the language ranking. Recently, the company suddenly became a group that wanted to use the go language as the development language. I may be too idle at ordinary times and could not play a major role in the group, so I was transferred to make up for it. It's only now that we know how wonderful the bug was. Although I do not like the word "front-end development", it is also a little basic. I can quickly find a breakthrough when encountering problems. Now, I have never heard of it, and I have learned from it. There is no way. I hope that through this period of study, I will get rid of the bad habit of procrastinating. The boss said, taking more notes is always excellent. (Well, I can't remember the original words because it means much in the original article)

Let's talk less and start recording the progress of today's learning. The basics of control statements and arrays have been fully read, and many small programs have also been implemented. There are also some special situations that need to be remembered that have not been carefully read. I plan to read these e-books several more times.

The general program structure is like this. You need to have a package and import the package. The most awkward thing is that there are no parentheses in the brackets, and there are various prescribed line breaks. Because I used to use Java before, I may add a semicolon to it if I don't move. In the go language, there can be no semicolon at the end of the statement because it will automatically add a semicolon, which is a problem. If you do not write the statement in the specified format, there is no way to compile the go compiler successfully, and there will be a syntax error. For example, in Java, {} can follow the judgment condition or start another line, but in go, it must follow the judgment condition. At the beginning, I was so upset that I was always wrong.

Although there are some awkward places, there are also open-minded places. Although I first came into contact with the go language, I was surprised by the switch. It's really awesome. It's so easy to get started with code.

In Java, the expression in the switch must be a constant or integer, while the go expression must be flexible. The switch can have expressions, but it can be directly entered into the case for judgment, just as there is no expression in the above example. Case may contain the determination of various conditions. It's good. This is an advantage that I have never seen in other languages.

The variable declaration in go is very characteristic. For example, the VaR A int statement declares an integer variable A, which is a bit like writing a MySQL database to create a table. The declared result in is somewhat similar to Java. Although it does not specify the value, it is assigned the default value of this type by default. It can also be declared as follows: temp: = 15 A statement completes variable declaration and initialization. If the data type is not explicitly specified, the variable is assigned a type based on the subsequent value type.

There is also a value assignment form: A, B: = 10, 16 is equivalent to a = 10, B = 16, it is really convenient.

In addition, for some mainstream programming languages, a function can return a maximum of one value, while the return value in go can be any one. The function is still learning ......

I learned this in three or four hours today, but I still have a meeting, and I don't understand it very well. I do feel that the gap between myself and those technical experts is still far away. Therefore, I must study hard and get rid of the cainiao hats as soon as possible.

Go continues ......

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.