https://www.cs.mcgill.ca/~cs520/2020/slides/10-golite-tutorial.pdf

Written by

in

GoLite is typically used as a subset of the Go programming language (Golang) designed for teaching compiler construction, or as a streamlined way to get started with the core principles of Go. It focuses on the essential syntax, types, and structures needed to understand the language’s design philosophy—readability and efficiency. 1. Basic Syntax

GoLite (and Go) syntax is designed for simplicity, reducing cognitive load.

Package Declaration: Every file must start with package main (for executable programs).

Imports: Import necessary packages, like import “fmt” for formatted I/O.

The Main Function: Execution starts with func main() { … }.

No Semicolons: Semicolons are not required at the end of lines.

Variables: Declared using var name type or using the short declaration operator := (e.g., x := 10). 2. Basic Types GoLite supports essential data types: Integers: int, int32, int64 Floats: float64 Strings: “Hello” Booleans: true or false Types: Variables are typed, ensuring type safety. 3. Structures and Control Flow

Structures (Structs): Used to define complex data types (similar to records). type Person struct { Name string Age int } Use code with caution.

Control Structures: Uses if, else, and for loops. Note that parentheses () are not used around conditions. Loops: Go only has one loop keyword: for. for i := 0; i < 10; i++ { fmt.Println(i) } Use code with caution. 4. Getting Started: “Hello, World!”

To get started with Go, you can install it on PC, Mac, or Linux, for example via sudo apt install golang on Ubuntu.

package main import “fmt” func main() { fmt.Println(“Hello, GoLite!”) } Use code with caution.

Running it: Use go run main.go in your terminal to compile and run the code immediately. If you’d like to dive deeper, I can provide examples of: Functions with multiple return values. Pointers in Go. Slices and Maps. Let me know which topic you’d like to explore first. Learn Go Like a Pro: Step-by-Step for Beginners

Comments

Leave a Reply

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