
- We will start with the traditional "Hello World" program which will appear in 1978 in the C programming language.
- C language influenced directly on Go.
- We assume that you have programmed in one or more languages whether compiled like c, c++, java or interpreted python, ruby, javascript.
- Go is compiled language.
- The Go toolchain converts source code. These toolchain accessed by a single command called go and multiple subcommands (run, build).
- $ go run hello_world.go
- prints -
- Hello World, 世界
- Go handles Unicode. so it can process text in all languages.
- If the program is more than a one-shot experiment means we run a file any time without processing used build subcommand.
- $ go build hello_world.go
- This creates an executable binary file called hello. that file can run anywhere without further processing
- $ ./hello_world
- Hello World, 世界
- Let's talk about the program :
- Packages: Go code is organized into packages modules which are similar to libraries and modules in other languages.
- Go packages consists of one or more .go source file in a single directory
- Each source file begins with package declaration( package main) and another package which is followed by a file import.
- package main is special. it defined a standalone executable program, not a library
Gofmt :
- Gofmt is a tool that automatically formats go source code.
Usage :
gofmt [flags] [path ...]
Why Gofmt :
- Easier to write: never worry about minor formatting concern while hacking away,
- Easier to read: when all code looks the same you need not mentally convert others formatting style into something you can understand.
- Easier to maintain: mechanical changes to the source don't cause unrelated changes to the file's formatting; diffs show only the real changes.
- uncontroversial: never have a debate about spacing or braces ever again!
Note :
On the survey of Go package Found that about 70% of them are formatted according to gofmt's rules.
This was more than expected.
To format your code, you can use the gofmt tool directly :
- $gofmt -w hello_world.go
Reference :
On the survey of Go package Found that about 70% of them are formatted according to gofmt's rules.
This was more than expected.
To format your code, you can use the gofmt tool directly :
- $gofmt -w hello_world.go
Command Line Arguments
Command line arguments is a parameter supplied to the program when it is involved.
Reference :
- https://blog.golang.org/
- https://tour.golang.org/welcome/1
I'm really impressed with your writing skills, as smart as the structure of your weblog.
ReplyDeleteGoLand Full Crack
Waves v12 Complete Crack