Introduction
Go, often called Golang, is an open-source programming language designed for building simple, reliable, and efficient software. It is statically typed and compiled, meaning errors are caught before the program runs and the resulting binaries execute quickly. Go was designed to combine the ease of use of a dynamic language with the safety and performance of a compiled language, making it popular for building servers, command-line tools, and cloud infrastructure.
Cricket analogy: Go being statically typed and compiled, catching errors before running, is like a pre-match pitch inspection catching a dangerous crack before a single ball is bowled, rather than discovering it mid-innings.
Syntax
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}Explanation
Every Go program starts with a package declaration; executable programs use package main. The import statement brings in the fmt package, which provides formatted I/O functions such as Println. The func main() block is the entry point of the program, and execution begins there when the compiled binary runs.
Cricket analogy: package main and func main() being the entry point is like every match officially starting with the toss; nothing in the game happens before that designated starting point.
Example
package main
import "fmt"
func main() {
name := "Developer"
fmt.Printf("Welcome to Go, %s!\n", name)
}Output
Welcome to Go, Developer!Key Takeaways
- Go is a statically typed, compiled language created for simplicity and performance.
- Every executable Go program has a package main and a func main() entry point.
- The fmt package handles formatted input and output.
- Go compiles to a single native binary, making deployment straightforward.
- Go is widely used for backend services, CLI tools, and cloud-native software.
Practice what you learned
1. What is the entry point function for an executable Go program?
2. Which package is commonly used for formatted printing in Go?
3. Is Go a statically typed or dynamically typed language?
4. What does compiling a Go program produce?
5. Which package declaration is required for a Go program to be executable?
Was this page helpful?
You May Also Like
History and Evolution of Go
Learn how Go was created at Google in 2007 and evolved into a widely adopted language for modern software.
Features of Go
An overview of Go's core language features, including concurrency, garbage collection, and simple syntax.
Setting Up a Go Environment
Step-by-step guide to installing Go, understanding modules, and running your first program.
Variables and Data Types in Go
Learn how Go declares variables with var and :=, and the built-in types like int, float64, bool, and string.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics