[Go language] 1. Getting Started Hello, world

Source: Internet
Author: User
Tags uppercase letter

Go Introduction

 

Why does Google release the go language when it comes to system programming-Level C/C ++ and later Java, as well as Scripting-level Ruby/perl/python?

"We developed go because the difficulty of developing programs in the last 10 years has made us a little frustrated"
-- Rob Pike, chief software engineer

 

Go fully supports coroutine, A coroutine, also known as a lightweight thread. Most languages do not directly support coroutine at the syntax level. Some languages may support coroutine through third-party libraries, but the functions are incomplete. For example, to create a coroutine,

Destroy and switch capabilities. If a synchronous Io is called in such a coroutine, such as network communication or local file read/write, other concurrent coroutines will be blocked. In this way, the goal of the coroutine itself cannot be truly fulfilled.

Go supports coroutine at the language level, called goroutine. All the system calls syscall provided by the go language, including all synchronous Io, will give the CPU to other goroutine.

The running mode is

func run (args string) {    //...}func main() {    go run(“go”)}

 

It's cool to implement concurrent coroutine operations with only one go keyword.

Go emphasizes the forced unification of style. The public variable must start with an uppercase letter, and the private variable starts with a lowercase letter, so that the public and private modifiers do not need to be displayed.

At the same time, go has mandatory requirements on the START "{" of the code block. For example

If expression {// This is required} If expression {// compilation error}

It can be seen that it is mandatory. In C ++/Java, both styles are allowed, which obviously leads to some inconsistent styles.

The first error handling method in go is also cool. The following describes the usage of the keyword defer.

f,err = os.open(filename)if err != nil {    log.Println("open failed")    return}defer f.Close()

Here, defer ensures that when the function exits, F resources will be released regardless of the cause of the exception.

At the same time, go also supports multiple return values, although it is also supported by the Dynamic Language Python.

A defer will let you discard the nested try in Java... Catch... Finally.

The heavy loads of operators and operators are not supported in go. The heavy loads provided in C ++/Java solve some OOP problems, but bring complexity.

In go, the constructor and destructor are abandoned, without virtual functions or vptr. Therefore, the overhead of objects in OOP is minimized. In Google's view, go is a practical style, not an academic style.

Go accepts functional programming ideas, supports goroutine and channels, and supports anonymous functions and closures. It can be said that go is the most open language in terms of system-level languages.

Go programming environment construction

Download the installation package directly:

http://gopher.qiniudn.com/download/go/go1.3.windows-amd64.zip

Decompress the go top-level directory and copy it to C: \ go.

After you configure the environment variable to path, you can see the go version information in the command line.

.

There are many options for the go editor. Here, select sublime. Type Hello, world, run the program, and finish the first lesson of go learning.

 

Reference Book go programming: http://www.amazon.cn/s/ref=nb_sb_ss_ I _0_6? _ Mk_zh_cn = % E4 % Ba % 9A % E9 % A9 % AC % E9 % 80% 8A % E7 % BD % 91% E7 % AB % 99 & url = search-alias % 3 daps & field-KEYWORDS = go % E8 % af % ad % E8 % A8 % 80% E7 % BC % 96% E7 % A8 % 8B & sprefix = go % E8 % af % ad % e8 % A8 % 80% E7 % BC % 96% E7 % A8 % 8B % 2 caps % 2c173 & RH = I % 3 AAPs % 2CK % 3ago % E8 % af % ad % E8 % a8 % 80% E7 % BC % 96% E7 % A8 % 8b

Related Article

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.