The document provides an overview of the Go programming language. It discusses that Go was designed by Google to help solve their large-scale programming problems. It then summarizes Go's history, purpose, features, and syntax elements such as data types, operators, functions, concurrency using goroutines and channels. The document also provides examples of Go code and concludes that Go has emerged as a popular language for cloud infrastructure due to its simplicity, concurrency, and performance.
1. The Go Programming Language
Seminar Guide:
Ms. Alby S.
Assistant Professor
Dept. Computer Applications
Presented by:
Basil N G
Roll No:17
MCA S5 R
2. Go is a programming language
designed by Google to help
solve Google's problems.
What is Go?
And has big
problems!
3. Which (big) problems?
● Hardware is big and the software is big
● There are many millions of lines of software
● Servers mostly in C++ and lots of Java and Python
● Thousands of engineers work on the code
● And of course, all this software runs on zillions of
machines.
4. A lot of others people
help to bring go from
prototype to reality.
Go became a public
Open Source
project.
2008 2009 20102007
Starts to have
adoption by other
programmers
Started and built by
Robert Griesemer,
Rob Pike and Ken
Thompson as a
part-time project.
History
5. ● Ken Thompson (B, C, Unix, UTF-8)
● Rob Pike (Unix, UTF-8)
● Robert Griesemer (Hotspot, JVM)
...and a few others engineers at Google
Who were the founders?
6. ● Eliminate slowness
● Eliminate clumsiness
● Improve productive
● Maintain (and improve) scale
It was designed by and for people who write, read,
debug and maintain large software systems.
Go's purpose is not to do research programming
language design.
Go's purpose is to make its designers' programming
lives better.
Why Go?
7. Go is a compiled, concurrent,
garbage-collected, statically typed
language developed at .
What is Go?
8. build
run
clean
env
test
compile packages and dependencies
compile and run Go program
remove object files
print Go environment information
test packages and benchmarks
Go is a tool for managing Go source code...
Mainly tools:
Others tools:
fix, fmt, get, install, list, tool,
version, vet.
9. Who are using today?
https://github.com/golang/go/wiki/GoUsers
10. ❏ Compiled
❏ Garbage-collected
❏ Has your own runtime
❏ Simple syntax
❏ Great standard library
❏ Cross-platform
❏ Object Oriented (without inheritance)
❏ Statically and stronger typed
❏ Concurrent (goroutines)
❏ Closures
❏ Explicity dependencies
❏ Multiple return values
❏ Pointers
❏ and so on...
What will you see in Go?
11. Have not been implemented in
favor of efficiency.
❏ Exception handling
❏ Inheritance
❏ Generics
❏ Assert
❏ Method overload
What will you not
see in Go?
13. A Go program basically consists of
the following parts :−
Package Declaration
Import Packages
Functions
Variables
Statements and Expressions
Comments
15. Go - Data Types
Boolean types
They are Boolean types and consists of the two predefined
constants: (a) true (b) false
Eg: var abc bool = true
Numeric types
They are arithmetic types and they represents
a) integer types (uint8-uint64, int8-int64, byte, rune, uint, int
b) floating point values (float32-float64)
(complex64-complex128)
Eg: var num int32 = -123
16. Contd…
String types
A string type represents the set of string values.
Its value is a sequence of bytes.
Eg: var str string =“hello”
Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types,
(d) Union types (e) Function types f) Slice types g) Function types
h) Interface types i) Map types j) Channel Types
18. Operator Meaning
= = equal to
!= Not Equal to
< Less than
> Greater than
<= Less than or
equal to
>= Greater than or
equal to
Operator Meaning
+ add
- Subtraction
* Multiplication
/ Division
% modulus
++ Increment
-- Decrement
1. Arithmetic Operators 2.Relational Operators
19. Operator Meaning
&& Logical AND
| | Logical OR
! Logical NOT
Operator Meaning
& Logical AND
| Logical OR
^ Logical NOT
<< Binary Left Shift
>> Binary Right Shift
3.Logical operators 4.Bitwise operators
5.Miscellaneous Operators
Operator Meaning
& Returns the address of a variable
* Pointer to a variable
20. Go – Decision Making
if statement
Consists of a boolean expression followed by one or more
statements.
package main
import "fmt“
func main() {
if n:=8; n%4 == 0 {
fmt.Println("8 is divisible by 4")
}
}
There is also if... else and nested if statements
21. switch statement
A switch statement allows a variable to be tested
for equality against a list of values.
os := "wndows"
switch os {
case "darwin":
fmt.Println("OS X.")
case "linux":
fmt.Println("Linux.")
default:
fmt.Printf("%s.", os)
}
Contd…
22. Go- Loops
For Loop
It executes a sequence of statements multiple times and
abbreviates the code that manages the loop variable.
• Go has just for as looping structure
• It is very similar with C or Java code, except for ( )
• Start and end declarations can be empty
Eg: for i:=0;i<5;i++ {
fmt.Printf("%d",i)
if i==3 {
fmt.Println("bye")
break
}
}
23. For is Go's "while“
At that point you can drop the semicolons: C's while is
spelled for in Go.
Eg: sum := 1
for sum <= 10 {
sum += sum
}
fmt.Println(sum)
Forever
If you omit the loop condition it loops forever, so an infinite
loop is compactly expressed.
Eg: for{
}
24. The deferred call's arguments are evaluated immediately, but the
function call is not executed until the surrounding function
returns.
func main() {
defer fmt.Println("world")
fmt.Println("hello")
}
Defer
25. Go - Functions
func function_name( [parameter list] ) [return_types] {
body of the function
}
• A function declaration binds an identifier,
the function name, to a function.
• Multiple return values
• Named result parameters
26. Go – Multiple Return Values
func swap(x, y string) (string, string) {
return y, x
}
func main() {
a, b := swap("hello", "world")
fmt.Println(a, b)
}
One of Go's unusual features is that functions and
methods can return multiple values.
27. What more?
● Pointer
● Struct
● Matrix
● Slice
● Range
● Closure //func inside a func
● Map
● Value function
● Method
● Interface
● Stringer
● Error
● and a lot of more!!!
28. $ go run http.go
A web server
● It is just simple to build a web server with 15 lines or less!!
Could you belive that???
29. ● To execute a goroutine, just go!
● To send or receive information between the
goroutines, use channels
● Use the GOMAXPROCS environment variable to
define the amount of threads
Concurrency (goroutines)
30. $ go run goroutines.go
hello
world
hello
world
hello
world
hello
world
hello
● A goroutine is a lightweight thread managed by Go runtime
Goroutines
31. $ go run channels.go
17 -5 12
Channels
● Channels are typed's conduit through which you can send and receive
values with the channel operator <-
34. Conclusion
•In 2014, analyst Donnie Berkholz called Go the emerging language of
cloud infrastructure. By 2017, Go has emerged as the language of
cloud infrastructure. Today, every single cloud company has
critical components of their cloud infrastructure implemented in
Go including Google Cloud, AWS, Microsoft Azure and many more
•In Stack Overflow's 2017 developer survey , Go was the only
language that was both on the top 5 most loved and top 5 most
wanted languages. People who use Go, love it, and the people who
aren’t using Go, want to be.