1024programmer Java Go+Python dual language mixed development course part 02 go language basics

Go+Python dual language mixed development course part 02 go language basics

Part 2 Go Language Basics

2.1 go language introduction

www.cnblogs.com/qfru/p/1060…

2.1.1 Go language introduction

google open source

Many Internet technologies are open sourced by Google

go core team

cloud.tencent.com/developer/a…

go creative background

Many systems within Google are built in C++, but the compilation process is too slow. In addition, the language itself is complex, and the development process of many languages ​​​​is to continuously add functions.

As a result, the language is becoming more and more bloated, and with the development of the Internet, it is better to develop a separate language. The representative of this language is js, a patch language, which was developed in 7 days at the beginning

The initial purpose of the go language is to replace c++. We will see later that go advocates simplicity and efficiency: it inherits but abandons many features that are rarely used in c++. The more functions the better, c and c++ are an example

The current mainstream programming languages ​​are basically from before 2000:

 c 1972
  c++1983
  python 1991
  java 1995
  php 1995
  JavaScript 1995
 

In the middle of 2005, amd released a dual-core processor, and multi-core became popular, but now the mainstream programming language has released the development node of the go language

2.1.2 Core features of go language

Static language (compiled language)

2.1.3 Advantages of go language

Simple syntax - reference to multiple languages, you can see a lot of shadows of c, and python
 High development efficiency
 Good execution performance - catching up with and exceeding Java
 Concurrent programming
 Compilation speed
 Easy to deploy
 

2.1.4 What can the go language do

Server-side development gin beego

Container virtualization dockerk8s
 Storage etcd
 tidb
 influxdb
 groupcache
 Blockchain
 Ethereum
 fabric
 microservices
 Ecology is getting better and better
 

2.1.5 current development trends of go

  1. Go development in China is faster than abroad

  2. Domestic recruitment demand is growing rapidly

Alibaba
 Tencent
 Baidu
 ByteDance
 Station B
 Millet
 Didi
 Jingdong
 360
 Qiniuyun
 Know almost
 Meituan
 

dubbo-go Many domestic manufacturers have begun to support go, and go has become the first batch of supported languages

2.2 Variables and Constants

2.2.1 How to define variables

1 single declaration variable

The var name type is the syntax for declaring a single variable.

  1. The first method is to specify the variable type. If no value is assigned after declaration, the default value will be used
var name string
 name="bobby"
 
  1. The second type is to determine the variable type based on the value (Type inference)

If a variable has an initial value, Go will automatically be able to use the initial value to infer the variable’s type. Therefore, you can omit the type from the variable declaration if the variable has an initial value.

var name="bobby"
 
  1. Third method, omit var, note: = The variable on the left should not have been declared (when multiple variables are declared at the same time, at least one must be a new variable), otherwise it will cause a compilation error (short declaration)
var a int = 10
 var b = 10
 c : = 10
 

This method can only be used within the function body and cannot be used for declaration and assignment of global variables

package main
 var a = "bobby"
 var b string = "imooc"
 var c bool

 func main(){
     println(a, b, c)
 }
 

2 Multi-variable declaration

**
**

  1. The first type, separated by commas, separates declaration and assignment. If no value is assigned, there is a default value
var name1, name2, name3 type
 name1, name2, name3 = v1, v2, v3
 
  1. The second type is direct assignment. The following variable types can be different types
var name1, name2, name3 = v1, v2, v3
 
  1. The third type, collection type
var (
     name string
     age int
 )
 

Note:

  • Variables must be defined before they can be used
  • Go language is a static language, requiring that the type of the variable and the type of the assignment must be consistent.
  • Variable names cannot conflict. (The same action cannot conflict within the domain)
  • Short definition method, at least one variable name on the left is new
  • Short definition method, global variables cannot be defined.
  • The zero value of the variable. Also called default value.
  • You must use variables once they are defined, otherwise they will not pass compilation.

If we cannot use an initialization statement for a variable with the same name again in the same code block, for example: a := 20 is not allowed, and the compiler will prompt the error no new variables on left side of := , but a = 20 is OK, because this is assigning a new value to the same variable.

If you use variable a before defining it, you will get the compile error undefined: a. If you declare a local variable but not in the same code��There is no need to occupy the variable name and there is an extra placeholder.

Note: There is no problem if a variable name is declared in python and is not used in subsequent code, but if a variable is declared and not used in go language, an error will be reported, so anonymous variables will be more commonly used in go language.

2. Define anonymous variables in go language

func test() (int, error) {
     return 0, nil
 }

 func main() {
     _, err := test()
     if err != nil {
         fmt.Println("Function call successful")
     }
 }
 

Note: In line 6 of code, anonymous variables are used when receiving the return value of the function. Because here we do not print the returned value but only care whether the function call is successful

2.2.4 Summary of this chapter

Here is the Yuque document, click the link to view: www.yuque.com/bobby-zpcyu…

2.3 Quick literacy on computer composition principles

2.3.1 Why we need to learn the principles of computer composition

  • Why are computer composition principles important?
    a. Must take the postgraduate entrance examination – its importance is self-evident
    b. Without the principles of computer composition, it would be difficult to learn the principles of operating systems.
    c. How important are operating system principles?
    ⅰ. What is virtual memory
    ⅱ. How to schedule multi-processes and multi-threads
    ⅲ. What are locks and deadlocks
    ⅳ. If you don’t understand the principles of the operating system – don’t even think about having a deep understanding of various components – redis, es, rabbitmq, etc.
    d. What is an interrupt, and why does IO operation actually not consume CPU?
    e. Many components and frameworks will change, but the principles of computer composition and operating systems will not change
  • What knowledge do you have about the principles of computer composition?
    book.douban.com/subject/123…
  • We will explain the basic principles of computer composition
    a. The most basic knowledge points of computer composition principles that will be learned in the course
    b. Base and base conversion
    c. Some basic knowledge of ascii code table and memory
  • Why do we arrange this?
    a. Python shields us from many underlying details
    b. We need to know more about these details in static languages
    c. If the implementation does not know it, it will cause some trouble in learning static languages
  • How to learn the principles of computer composition
    This knowledge must be remembered for us, but you have to know the basics. Don’t let others mention it to you later or read information on the Internet that omits these basics and you don’t know.
    It is unrealistic to remember so many knowledge points. When you see many articles that explain the principles in depth, they will more or less involve operating system principles and computer composition principles

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/770316

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索