๐ŸนIntroduction to GoLESSON

Introduction to Go

What Makes Go Special

Go (also called Golang) is a compiled, statically typed language created at Google in 2009. Unlike Python or JavaScript โ€” which are interpreted at runtime โ€” Go compiles directly to machine code, making programs start fast and run efficiently.

Here is a quick comparison:

FeatureGoPythonJavaScript
TypingStaticDynamicDynamic
ExecutionCompiledInterpretedJIT/Interpreted
ConcurrencyBuilt-in (goroutines)Threads/asyncioEvent loop / Workers
MemoryGarbage collectedGarbage collectedGarbage collected

Go's syntax is intentionally small. There are no classes, no inheritance, and no operator overloading. What you get instead is a lean set of features that are easy to read and reason about โ€” something Python aims for but Go enforces through tooling and language design.

Anatomy of a Go File

Every Go source file begins with a package declaration. For a program you can run directly, the package must be named main:

  • package main โ€” tells the compiler this file belongs to the executable package.
  • import "fmt" โ€” brings in the standard-library package for formatted I/O.
  • func main() โ€” the entry point; execution starts here, just like main in C or Java.

Running this with go run main.go prints:

Exported Names

In Go, whether an identifier is visible outside its package is determined entirely by its first letter โ€” no public or private keywords needed.

The rule: an identifier that starts with an uppercase letter is exported (accessible from other packages). One that starts with a lowercase letter is unexported (package-private).

This is why fmt.Println is capitalized: Println is exported from the fmt package so that your code โ€” living in a different package โ€” can call it. If you try to call the hypothetical lowercase version fmt.println, the compiler rejects it immediately:

The rule applies uniformly to functions, types, variables, constants, struct fields, and methods โ€” anything declared at package level follows the same capitalization convention.

Practical implication: when you import a package, you can only reference its exported (uppercase) identifiers. Everything lowercase is the package's internal implementation detail โ€” the compiler enforces this boundary so you never need to read the source to know what is part of the public API.

fmt.Println

fmt.Println writes its arguments to standard output followed by a newline. Multiple values are separated by spaces automatically:

Unlike console.log in JavaScript or print in Python, Println always appends a newline โ€” no trailing \n needed.

fmt.Printf and Format Verbs

fmt.Printf gives you C-style format strings but with Go's own verbs:

VerbMeaning
%sString
%dInteger (decimal)
%fFloating-point
%vDefault format for any value
%+vStruct with field names
%#vGo syntax representation
%qQuoted string
%02dZero-padded integer
%TType of the value

Output:

%v is the all-purpose verb โ€” reach for it when you just want to see a value without caring about exact formatting. %T is especially useful while learning because it reveals what type Go inferred.

The Go Toolchain

Go ships with a complete toolchain. You will use these commands constantly:

Every Go project is a module, identified by its go.mod file. The module path (e.g., github.com/you/myapp) is used in import statements. For the small playground programs in this course you can skip go mod init โ€” the playground handles that for you.

gofmt enforces a single canonical style. There is no debate about tabs vs spaces in Go: the answer is always tabs, enforced by tooling.

The Standard Library

Go's standard library is unusually comprehensive. Before reaching for a third-party package, check if stdlib already has what you need:

PackagePurpose
fmtFormatted I/O
net/httpHTTP client and server
encoding/jsonJSON marshal / unmarshal
stringsString manipulation
strconvNumber โ†” string conversions
osFile system and environment
syncMutexes, WaitGroups
errorsError creation and inspection

You will use most of these packages before you finish this course.

Go's Philosophy of Simplicity

Go was designed with one guiding principle: simplicity scales. A small language means faster onboarding for new team members, consistent code style across large codebases, and fewer surprises at 2 am when something breaks in production. As you work through this course, you will see that most Go code looks the same whether it was written by a beginner or a ten-year veteran. That consistency is the point.

Knowledge Check

What must every executable Go program's package be named?

Which identifier can be used from outside its package?

What is the entry point function of a Go program?