Go (golang) is a programming language created at Google in 2007 by
Robert Griesemer, Rob Pike, and Ken Thompson.It was first announced in
November 2009.
The purpose of creating the language is to design a systems programming language for large
distributed system.It is now used in some of Google's
production systems.
Go (golang) is a programming language created at Google in 2007 by
Robert Griesemer, Rob Pike, and Ken Thompson.It was first announced in
November 2009.
Any thing about golang can be found at https://golang.org.
It is a little bit hard to place a specific paradigm about golang. Firstly, it is imperative: it has loops, statements and etc (2). And go is little Objected Oriented : Since it looks more like C than C++ and Java. For example, there are basic types such as int. And there is also object but object is just called "struct" in golang (1). Concurrent programming: Go has native support for concurrent operations. The concurrency in Go includes multi-threading, multi-processing, and asynchrony (3).
1. https://golang.org/doc/faq#Is_Go_an_object-oriented_language
2. https://golang.org/ref/spec#Statements
3. https://vimeo.com/49718712
Golang is strongly typed and garbage-collected.
Functions are not necessarily first-class objects but golang does support
it.
Programmers are allowed to create new types in golang?
Unfortunately it's not easily possible to create new types in golang since
Go is a statically typed language and the linker will eliminate dead code.
In golang, there is switch statements just like it in Java.
And there is a "select" statement in golang which lets a group wait on
multiple communication operation.
For loop and if and else statements are slightly different with C. One
example is below:
package main import "fmt" func pow(x, n, lim float64) float64 { if v := math.Pow(x, n); v < lim { return v } else { fmt.Printf("%g >= %g\n", v, lim) } // can't use v here, though return lim } func main() { sum := 0 for i := 0; i < 10; i++ { sum += i } fmt.Println(sum) }
https://tour.golang.org/flowcontrol/
An interesting point about golang is there is no while loop in go
but you can use a "for" to do a while loop.
And yes, you have "continue" and "break" in go and they do the same
thing here just like C.
As said in Typing System, it's not easy for a programmer to create a
new abstraction (object). But the language itself does offer programmers a
lot of abstract types.
A list of types of golang can be found here:
https://golang.org/pkg/go/types/
Golang's syntax is using Extended Backus-Naur Form. It seems like to
be more modernized than C and Java and C++.
There is one thing about golang that I personally really hate about
it. That is, as a C family language, the developers seem to try their best to
make golang's syntax unlike C's. No idea why they want to do that. Maybe they
want golang more modernized? One example is:
// in c you do: type someStruct struct{ int i; char j; } int x =10; char c='c'; // in go you do: type someStruct struct{ i int j char } var i = 10 var j = 'c'
Also, '=' is the assignment operator but ':='. All those difference make programmers from C/C++ not that easy to get golang fast. So I would they can make the syntax more similar to other C family languages.
Golang is lexically scoped(staticly scoped). A small example is here:
// go run static-scope.go package main import "fmt" var a = 1 func foo(){ a = 2 fmt.Println("in foo, a is", a) } func main(){ var a = 0 fmt.Println("in main, a is", a) foo() fmt.Println("after foo() call, a is", a) } /////
And by runing this piece of golang code, you would get a result as:
in main, a is 0
in foo, a is 2
after foo() call, a is 0.
And how storage is allocated in golang? Well, you shouldn't really worried
about this but a short answer here is it's a combination case of heap and stack.
So in the current compilers, if a variable has its address taken, then that
variable is allocated on the heap. And in some other cases, a variable can reside
on the stack.
A big change in Go from c and c++ is the garbage collection. However, people
would think that garbage colllection would cause the longer runtime/slower performa-
-nce. A great example is Java. Similar to golang, java is from C and it has the
automatic garbage collection. And we know, java is slow :( .
However, the devolopers of Go say this:
it's critical to eliminate that programmer overhead, and advances in garbage
collection technology in the last few years give us confidence that we can implement
it with low enough overhead and no significant latency.
https://kuree.gitbooks.io/the-go-programming-language-report/content/11/text.html
One thing that golang's developers have tried to do is to make the language
easier for people to get. That means the golang really supports the efficiency. But
the language itself is not that abstract so I would say golang has a similar efficiency with
Java.
Programmer get a better security/reliability in golang compare to those
dynamic language.
However, this language won't be considered to have strong security. Yes, you
have to handle all the errors just like in C.
Unlike Java, go is not run on a virtual machine. This does make the language
run faster but just make your programming harder.
The language does support the extensibility. Like importing a package is easy.
By doing this, programmers can have hundred types of type from libraries. Also, golang
allows programmer to create their own types like what we can do in C.
Though go doesn't allow programmer to write the syntax and semantic.