1. Introduction to Go Language
GDGDEVFESTBAGUIO -CAR 2014
UNIVERSITY OF BAGUIO
TZAR C. UMANG
ICT DIRECTOR –HIVE INC.
2. Flow of discussion
Requirements
Introduction
Basics
Sample Deployment
3. Requirements
Development
Software Development Kit and Test Environment
You can use Appengine’sGo SDK: https://cloud.google.com/appengine/downloads
Python 2.7 (please don’t use the newest version)
IDE
You can use Sublimetxtand notepad++
If your on the cloud you can use Github’sonline IDE
Pushing files when Deploying
Git: http://git-scm.com
4. Requirements
Development Servers
Highly recommend Google’s Appenginefor Go Language
You can also use Openshift’sGo Language Environment, but you will not have access to Appengine’sfunctionalities
Deployment
You can use Appengine+ Cloudcomputeof Google
Or OpenshiftBig Gear
5. Young Language
Created by: Robert Griesemer, Ken Thompson, and Rob Pike (Googlers) in late 2007
Brought to public in 2009
A new systems programming languagefor the past 10 years +
It is fastto develop, compileand run
Answer to hardware’s limitations today, yet future proofing your system, where the language handles routine and memory management
Funand Easymaking developmentmore productiveand we don’t use semicolons “;”
Uses goroutines, a lightweight communicating processes and its concurrent, multiplexing of it onto threads is done automatically
Has a good garbage collection, it is efficient and low in latency
7. Basics
Comments
Uses /**/ or //
// for line by line comment
/**/ for large chunk disabling of function or a big header credit on your code
8. Basics
Formatting
Indention is just like any other IDE for any PL tab works for them
gofmthandles alignment on you code
Parenthesis
Go uses lesser parenthesis
Structures like if, for and switch don’t require it
Operator precedence hierarchy is shorter and clearer
x<<8 + y<<16 //spaces implies what it means
9. Basics
Semicolons “ ; “
We don’t usually use it to terminate a line just like python
Mostly used to separate clauses of for –loops and the like
Making codes cleaner on the eye
10. Basics
If –statement
It looks as simple as this
if a > 1 {
return b
}
It also accept initialization statements, to setup a local variable
if err := datastore.Get(c, key, &b); err != nil {
return err
}
11. Basics
Loop
Unified for and while, there is no do-while
For
for init; condition; post { }
While
for condition { }
For(;;)
for { }
No comma operator and “+ +” and “--” are statements not expression
//Reversea
fori,j:=0,len(a)1;i<j;i,j=i+1,j1{
a[i],a[j]=a[j],a[i]
}
To run multiple variables you need to use assignments
12. Basics
Switch
Go uses a more general implementation of switches
Expressions don’t need to be constants or even integers
Cases are evaluated top to bottom until a match is found
And if switch has no statement it switches to “true”
Making it possible to write if-else-if-else-if-else chain as a switch
14. Basics
Switch
Cases can be presented into commas as well
funcrunOver(cbyte)bool{
switchc{
case'','?','&','=','#','+','%':
returntrue
}
returnfalse
}
16. Basics
Strings
It is built in, these are immutable values not just arrays of bytes values.
You can’t change a string variable once it is built
Though you can use snippets to change or to reassign string variables
s:="hello"
ifs[1]!='e'{os.Exit(1)}
s="goodbye"
varp*string=&s
*p="ciao"
17. Basics
Arrays
Declared this way
vararrayOfInt[10]int;
They are like strings with values though mutable
Arrays holds values in Go making it as meaningful as a string, not like with other language such as C where arrays are pointers
18. Basics
Pointers
We have them but they are limited
No pointer arithmetic
Easier for garbage collection
22. Requirements
Development
Software Development Kit
You can use Appengine’sGo SDK: https://cloud.google.com/appengine/downloads
Python 2.7 (please don’t use the newest version)
IDE
You can use Sublimetxtand notepad++
If your on the cloud you can use Github’sonline IDE
Pushing files
Git: http://git-scm.com
23. Requirements
Development Servers
Highly recommend Google’s Appenginefor Go Language
You can also Openshift’sGo Language Environment, but you will not have access to Appengine’sfunctionalities
Deployment
You can use Appengine+ Cloudcomputeof Google
Or OpenshiftBig Gear
24. THANK YOU!!!
For Questions and Tutorials you may join the group
“Philippine Gophers” in FB and G+
Or add me in:
fb.com/tzarumang
twitter.com/definitelytzar
plus.google.com/tzarumang
Presentation is based from:
golang.org
Chris Lupo’sThe Go Programming Language