Introduction to GoLang by Amal Mohan N. This presentation is an introduction to GoLang - it's history, features, syntax, importance etc.
concurrency, go-routines, golang, google, gopher, introduction, programming
2. Discussion Points
● History of Go.
● What is Go?
● What you’ll see in Go.
● What will you not see in Go.
● Why Go?
● Features
● Important Points.
● Who all are using Go
● Go installation
● Go Tools.
● Go structure.
● Types, Variables and Statements
● FrameWorks.
● Go Scope
● Go Docs
● Drawbacks
3. Founders of Go.
Ken Thompson Rob Pike Robert Griesemer
Kenneth Lane Thompson is an
American pioneer of computer
science.Thompson worked at Bell
Labs for most of his career where
he designed and implemented the
original Unix operating system.
A Swiss computer scientist. He is best
known for his work on the Go. Prior to
Go, he worked on Google's V8
JavaScript engine, the Sawzall
language, the Java HotSpot virtual
machine, and the Strongtalk system.
Robert "Rob" Pike is a Canadian
programmer and author. He is best
known for his work on the Go
programming language and at Bell
Labs, where he was a member of
the Unix team.
5. What is Go?
● Go is Open-Source General-Purpose programming language
developed by Google.
● Solution to “BIG PROBLEMS” at Google.
6. What you’ll see in Go.
● Compiled
● Garbage Collection
● Simple Syntax
● Great standard library
● Cross Platform
● Object Oriented (no Inheritance)
● Statically typed
● Extensive use of pointers
● Extensive use of Structures
● Extensive use of Interfaces
● Extensive use of If statements
● Extensive use of for loops
● Multiple returns
7. What will you not see in Go.
● Exception Handling
● Inheritance
● Generics
● Assert
● Method Overloading
● Some loops
● Ternary Operator
8. Why Go?
● Simplicity
● Eliminates Slowness ( Performance ).
● Secure and Easy to Maintain code.
● Concurrency
● Good Hardware Interaction.
● Speed for Production.
● Easy read, write, debug, and Maintain Large Software Systems (Google).
● Community
For Starters
9. Why Go?
● Why Go was developed when there already was many popular languages?
Go was invented (in 2007) at a time when multicore CPU architectures were common.With multiple
cores, code can run in parallel on all available cores; but there was no programming language that
simplified the development of multithreaded applications. The responsibility of managing different threads
safely and efficiently fell on developers. Thread-locking, race conditions and deadlocks are usual
challenges. Go was designed with concurrent programming in mind.
Golang FAQ states that in the days before Go,
“One had to choose either efficient compilation,
efficient execution, or ease of programming; all
three were not available in the same mainstream
Language.”
10. Why Go?
● Why the Go Language Is Growing So Quickly?
Go is a programming language that’s only a decade old. It has rapidly grown in popularity for
optimization tasks that require lower level system access. In 2017, it was the fastest growing
language in the world, because it can handle many of the same tasks as C or C++. As those
languages have declined in popularity due to their complexity and confusing syntax, Go is
increasingly filling the gap left behind.
11. Go Features
1. Compile to Binary
One major strength of Go is it runs as a compiled application, without an interpreter or framework standing
in between. This means that Go compiles directly to binary machine code and runs directly. This makes Go
faster, but it also means you don’t have to agree on and install the same interpreter on all machines. Go
just works.
1. Garbage Collection
Unlike other direct-compile languages, however, Go supports added features for system cleanup. With
garbage collection included, you don’t need to remember to free up pointers or think about dangling
pointers. All that gets done automatically.
12. Go Features
3. Statically Typed
In Go, you’ll need to declare types for all variables and function arguments at compile time. This increases
the security of the language and points out errors early in the programming process. Especially for projects
with many developers over a long period of time, static typing makes functions and libraries easier to
understand.
4. No Exceptions
Go forces developers to handle basic errors themselves rather than rely on a try catch block or other
standard exception logic solutions. When you write in Go, you have to plan ahead for failure scenarios and
think critically about what your program needs.
13. Go Features
5. Concurrency & Routines
Concurrency and parallelism aren’t the same thing. Parallel processing involves multiple processor cores
working on different problems at the same time. Concurrency involves breaking multiple computations up
into smaller chunks and scheduling them for concurrent work on a single processor. This means that
various threads get broken up and processed in small bits over time.
With the rise of microservices and the need for multiple database connections, message queues, and
memory caches simultaneously, concurrent processing becomes increasingly important. Parallel and
concurrent processing are not mutually exclusive, and in fact, Go is well-positioned to be the go-to
language for data centers adding cores and looking for increased systems efficiency with multi-threading.
A Goroutine is a lightweight thread. When initialized it has a stack of 4KB, smaller and faster to initialize
than typical threads. Routines are also not mapped one-to-one with OS threads, and a single routine can
run across multiple OS threads. This enables hundreds of thousands of routines to run concurrently and in
parallel. The Go runtime scheduler manages and schedules all these threads for execution.
14. Go Features
6. Maintainable Syntax
Google places a premium on code that’s easy to understand because they have thousands of
developers who need to be able to share and understand each others’ code. Go intentionally
leaves out a lot of features for the sake of simplicity. There are no classes in Go, for example, only
packages. There’s also no inheritance, constructors, annotations, or generics. Go is as simple to
read as Ruby or Python, but it competes with C/C++ in terms of efficiency. It’s also built to be
backward compatible, and the syntax has remained stable since launch.
15. Go Features
Other Features
1. Safe
2. C - inspired syntax
3. Multi paradigm
4. Great Standard library
5. Simplified Documentation
6. Fast
7. Light Weight
8. Open-Source
9. Build-in testing tool
10. Go - routines
16. Go Important points
1. Object oriented without inheritance
2. Syntax sugar declaration
3. Strong and static types
4. Functions and methods which has receivers
5. Visibility based on the Case of First letter
6. Unused imports and variables causes errors
7. Excellent and complete standard library
8. Cross compilation capability
19. The Go Tool
The go tool is the standard tool for building, testing, and installing Go programs.
Compile and run hello.go:
Run zip tests:
Build and format the files in the current directory:
20. The Go Tool
The go tool is the standard tool for building, testing, and installing Go programs.
Fetch and install websocket:
Tool Commands :
● build - compile packages and dependencies
● clean - remove object files
● env - print go environment information
● fix - run go tool fix on packages
● fmt - run go fmt on package sources
● get - download and install packages and dependencies
● install - compile and install packages and dependencies
● list - list the packages
● run - compile and run go program
● test - test packages
● tool - run specified tool
● version - print go version
21. Go Structure
1. Package declaration
2. Import statements
3. Variables
4. Statements and Expressions
5. Functions
6. Comments
22. Go Datatypes
1. Basic type: Numbers, strings, and booleans come under this category.
2. Aggregate type: Array and structs come under this category.
3. Reference type: Pointers, slices, maps, functions, and channels come under this
category.
4. Interface type
23. Go Variables
1. var <v_name> <type>
2. var <v_name> <type> = expression
3. var <v_name> = expression
4. <v_name> := expression
30. Go Control Statements
● Go do not has while loops
● Go only has for loops
● For loops serves different purposes using different format
Traditional For loop :
33. Go Frameworks
● Gin
Gin is an HTTP web framework written in Go that is immensely popular with over 50k
stars on Github at the time of posting.
● Beego
Beego is another Go web framework that is mostly used to build enterprise web
applications with rapid development.
34. Go Frameworks
● Iris
Iris is an Express.js-equivalent web framework that is easier to use for
people coming from the Node.js community.
● Echo
Echo is another promising framework created by Labstack with 20k stars
on GitHub.
35. Go Frameworks
● Fiber
Fiber is another Express.js-like web framework written in Go that
boasts low memory usage and rich routing. Built on top of the
Fasthttp HTTP engine for Go
37. Go Scope
Aside from building general web applications, the language’s scope encompasses a wide range of use
cases:
● Command line application
● Cloud-native development
● Creating utilities and stand-alone libraries
● Developing databases, such as CockroachDB
● Game development
● Development operations
38. Go Docs and websites
Official Support
● https://go.dev/doc/
● https://go.dev/play/
● https://pkg.go.dev/
Other Support
● https://devdocs.io/go/
● https://www.golangprograms.com/go-language.html
● https://join.slack.com/t/gophers/shared_invite/zt-11ddswns3-S__IcQcJRsVqlmCDafl5_A
39. Go Drawbacks
1. Young Language, still developing
2. Absence of manual memory management
3. Error handling isn’t perfect
4. Lack of Function Overloading and Default Values for Arguments
5. Lack of Generics
6. No inheritance
40. Thank you.
Questions?
“Learn from yesterday, live for today, hope
for tomorrow. The important thing is not to
stop questioning.”
- Albert Einstein