Introduction to go language programming , benchmark with another language programming nodejs , php , ruby & python . how install go . use what IDE . and rapid learnin golang
1. Introduction to go language
programming
Mahmoud masih tehrani
Clickyab
Spring 2016
2. Golang history
Robert Griesemer, Rob Pike and Ken Thompson started sketching the goals for a new language on
the white board on September 21, 2007. Within a few days the goals had settled into a plan to do
something and a fair idea of what it would be. Design continued part-time in parallel with
unrelated work. By January 2008, Ken had started work on a compiler with which to explore ideas;
it generated C code as its output. By mid-year the language had become a full-time project and
had settled enough to attempt a production compiler. In May 2008, Ian Taylor independently
started on a GCC front end for Go using the draft specification. Russ Cox joined in late 2008 and
helped move the language and libraries from prototype to reality.
Go became a public open source project on November 10, 2009. Many people from the
community have contributed ideas, discussions, and code.
3. Go is multiplatform
Google's Go compiler, "gc", is developed as open source
software and targets various platforms including Linux, OS
X, Windows, various BSD and Unix versions, and since
2015 also mobile devices, including smartphones. A
second compiler, gccgo, is a GCC frontend.The "gc"
toolchain is self-hosting since version 1.5
4. Why go?
Go is easier to write (correctly) than C.
Go is easier to debug than C (even absent a debugger).
Go is the only language you'd need to know; encourages contributions.
Go has better modularity, tooling, testing, profiling, ...
Go makes parallel execution trivial.
6. How install go and use that!?
Install : sudo apt-get install golang
Show version : go version
>>go version go1.6.1 linux/amd64
Show help : go help
Run code : go run YOUR_PACKAGE_NAME.go
Compile code : go install YOUR_PACKAGE_NAME.go
7. Which IDE for go
● Sublime Text 2
● IntelliJ
● LiteIDE
● Netbeans
● Eclipse
● TextMate
● Komodo
● vim
● Emacs
8. Getting start to learn go
package main
import ("fmt")
func main() {
fmt.Println("Hello, )"ﻣﺣﻣود
}
9. Comment
// comments in which all the
text between the // and the end of the line is part of
the comment and /* */ comments where everything
between the * s is part of the comment. (And may in-
clude multiple lines)
10. Install packages
1. Download and install it:
$ go get github.com/gin-gonic/gin
2. Import it in your code:
import "github.com/gin-gonic/gin"
11. Types in go
Integer:
uint8 , uint16 , uint32 , uint64 ,
int8 , int16 , int32 and int64
Floating point:
float32 and float64
String:
string
13. strings
String literals can be created using double quotes
"Hello World" or back ticks `Hello World` . The differ-
ence between these is that double quoted strings can-
not contain newlines and they allow special escape se-
quences. For example n gets replaced with a newline
and t gets replaced with a tab character.
31. An Example Program
package main
import "fmt"
func main() {
fmt.Print("Enter a number: ")
var input float64
fmt.Scanf("%f", &input)
output := input * 2
fmt.Println(output)
}
35. If
func main() {
for i := 1; i <= 10; i++ {
if i % 2 == 0 {
fmt.Println(i, "even")
} else {
fmt.Println(i, "odd")
}
}
}
36. switch
switch i {
case 0: fmt.Println("Zero")
case 1: fmt.Println("One")
case 2: fmt.Println("Two")
case 3: fmt.Println("Three")
default: fmt.Println("Unknown Number")
}
38. Array
var total float64 = 0
for i := 0; i < len(x); i++ {
total += x[i]
}
fmt.Println(total / len(x))
>># command-line-arguments
.tmp.go:19: invalid operation: total / 5 (mismatched types float64 and int)