In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge of GO language structure. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Characteristics
Statically typed, compiled open source language.
Scripted syntax that supports multiple programming paradigms. There are functional and object-oriented.
Native, powerful concurrent programming support
advantage
Scripted grammar: easy to use.
Static type + compiled type: high running efficiency.
Native, support concurrent programming: reduce development and maintenance costs; better execution of programs.
Inferior position
Grammatical sugar is not as much as Ruby and Python.
The current program is not as fast as C.
Third-party libraries are not as rich as mainstream programming languages.
GO language structure
The basic components of the Go language are as follows: package declaration, introduction of packages, functions, variables, statements & expressions, comments
Next let's take a look at the simple code that outputs "Hello World!":
Package main
Import "fmt"
Func main () {
/ * this is my first simple program * /
Fmt.Println ("Hello, World!")
}
Let's take a look at the various parts of the above program:
The first line of code package main defines the package name. You must indicate which package the file belongs to in the first uncommented line of the source file, such as package main. Package main represents a program that can be executed independently, and each Go application contains a package called main.
The next line, import "fmt", tells the Go compiler that the program needs to use the fmt package (functions, or other elements), which implements the function to format IO (input / output).
The next line, func main (), is the function that the program starts executing. The main function must be included in every executable program, and it is generally the first function to execute after startup (if there is an init () function, it will be executed first).
The next line / *. * / is a comment and will be ignored when the program is executed. Single-line comments are the most common form of comments, and you can use single-line comments that start with / / anywhere. Multiline comments, also known as block comments, all begin with / * and end with * /, and cannot be used nested. Multiline comments are commonly used for documentation of packages or code snippets that are commented into blocks.
The next line, fmt.Println (...) You can output the string to the console and automatically add newline characters\ n at the end.
You can get the same result using fmt.Print ("hello, world\ n").
The Print and Println functions also support the use of variables, such as fmt.Println (arr). If not specified, they output the variable arr to the console in the default print format.
When identifiers (including constants, variables, types, function names, structure fields, etc.) begin with an uppercase letter, such as Group1, then objects using this form of identifier can be used by the code of the external package (the client program needs to import the package first), which is called an export (such as public in an object-oriented language) Identifiers that begin with lowercase letters are not visible to the outside of the package, but they are visible and available inside the entire package (like protected in object-oriented languages).
GO source file
A file whose name is suffixed with .go and whose content is organized in GO language code.
Multiple GO source files need to be organized in code packages.
classification
Command source file: declare that you belong to the main code package, including the main function with no argument declaration and result declaration.
Library source file: a source file that does not have the characteristics of a command source file.
Test the source file.
Code package
Action
1. The most basic part of compiling and archiving GO programs is.
two。 The effective organization of code partition, collection and dependency is also an auxiliary means of access control.
Rules
A code package is actually a directory represented by an import path, which is a subpath under / src or / pkg/.
Statement
1. Each source file must declare the code package to which it belongs.
two。 All source files in the same code package should declare the same code package.
These are all the contents of the article "what is the language structure of GO?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.