Get Set GO Lang
part# 1_________________________
What Is Go Lang?
(in case you just came here while curious web surfing)
Go is an OpenSource programming platform developed by Google (and contributors) to be expressive and efficient at the same point.
It's distributed under BSD-style License
It's a concurrency favoring, statically typed, compiler-based language. Though it declares to be giving ease like dynamically typed interpreted code.
_________________________
On your mark, Get Set GO
(getting started with the quick boost usage)
To directly start playing with Go Lang, visit http://play.golang.org/,
where you can directly type/paste in your go-lang code in an online editor and run to get output.
Just a small ++HelluvaWorld code-piece
package main
import ("fmt"
"time"
"os"
"math" )
func main() {[] Installing it for local & full-flown development practice http://golang.org/doc/install would guide you getting 'go' working on your Linux, FreeBSD, OSX & Win platforms.
fmt.Println("Today is ", time.Now().Weekday())
fmt.Println("env as ", os.Environ())
fmt.Println("A Pi on Ceil looks like ",
math.Ceil(math.Pi),
" and a Pie on Floor looks like",
math.Floor(math.Pi))
}
_________________________
Rewind before the Start Line and take your First Leap
(first useful step to starting use of Go Lang)
[] quickie at variables and constants, a look at GO's declaration style
// var used to declare variable with type at endnow, you also know '//' is to comment as in C/C++ and more.
var a, b, c int
// direct initialization doesn't require providing type
var x, y, z = 1, true, "yes"
// constants just require a 'const' keyword
const newconst = 10
func tellvar() {
a, b, c = newconst + 1, newconst + 2, newconst + 3
// inside a function, even := construct
// could be used to assign and not use 'var'
clang, java, ruby := "dRitchie", "jGosling", "Matz"
fmt.Println(a, b, c, x, y, z, clang, ruby, java)
}
[] mobilizing functions
just an emulation of 'math' libraries 'pow' method (also a look at using for loop)
package main
import "fmt"
func pow(x int, y int) int {
a := 1
for i := 0; i < y; i++ {
a = a * x
}
return a
}
func main() {
fmt.Println( "2 to the power of 5 is ", pow(2, 5) )
}
[] some function parameters style, the pow above is same as
func pow(x, y int) int { ... }
[] function returning multiple values
dream come true of how a function can return any number of values (also use of if condition)
func plusminus(a, b int) (int, int) {
if a > b {return a+b, a-b}
return a+b, b-a
}
or could be like
} else {
minus = b - a
}
return
}
func plusminus(a, b int) (plus, minus int) {
plus = a + b
if a > b {minus = a - b
} else {
minus = b - a
}
return
}
usage:
plus, minus := plusminus(1, 2)
fmt.Println("Plus: ", plus,
"\nMinus: ", minus)
[] more to go..... in more to come
_________________________
Shops to Go
(other fine links to Go, until next part of this tutorial comes)
- Home Portal: http://golang.org/
- A Tour of Go: http://tour.golang.org/#1
- Google I/O 2010 Go Lang: @youtube
- Google I/O 2011 Writing WebApps in Go: @youtube
- Go Hangout with Brad & Andrew: @youtube
- Mailing List: http://groups.google.com/group/golang-nuts
- IRC Channel: irc://irc.freenode.net/#go-nuts
- Twitter: http://twitter.com/go_nuts
- Blog: http://blog.golang.org/
- Dashboard for Go Language: http://godashboard.appspot.com/project
No comments:
Post a Comment