Presentation is loading. Please wait.

Presentation is loading. Please wait.

FASTFAST All rights reserved © MEP Make programming fun again.

Similar presentations


Presentation on theme: "FASTFAST All rights reserved © MEP Make programming fun again."— Presentation transcript:

1 FASTFAST All rights reserved © MEP Make programming fun again.

2 All rights reserved © MEP The Go Programming Language New Experimental Concurrent Garbage Collected Systems Language

3 All rights reserved © MEP Goals The efficiency of a statically-typed compiled language with the ease of programming of a dynamic language. Safety: type-safe and memory-safe. Good support for concurrency and communication. Efficient, latency-free garbage collection. High-speed compilation.

4 GO and C++ differences Go does not have classes with constructors or destructors. Instead of class methods, a class inheritance hierarchy, and virtual functions. Go uses garbage collection. It is not necessary (or possible) to release memory explicitly. Go does not support function overloading and does not support user defined operators. All rights reserved © MEP

5 GO and C++ differences Go has pointers but not pointer arithmetic. You cannot use a pointer variable to walk through the bytes of a string. Hash tables are provided by the language. They are called maps. Go does not use header files. Instead, each source file is part of a defined package.Import is used for declaration packages. All rights reserved © MEP

6 Syntax All rights reserved © MEP

7 Go Syntax Basic control structures are familiar: if a == b { return true } else { return false } for i = 0; i < 10; i++ {... } v1 := v2; equivalent var v1 = v2; Go permits multiple assignments, which are done in parallel. i, j = j, i; // Swap i and j. Functions may have multiple return values, indicated by a list in parentheses. func f() (i int, j int); v1, v2 = f(); All rights reserved © MEP

8 Go Syntax Go does not support enums. Instead, you can use the special name iota in a single const declaration to get a series of increasing value. const ( red = iota; // red == 0 blue; // blue == 1 green // green == 2 ) All rights reserved © MEP

9 Dynamic Allocation Go has a builtin function new which takes a type and allocates space on the heap. The allocated space will be zero-initialized for the type. For example, new(int)allocates a new int on the heap, initializes it with the value 0, and returns its address, which has type *int. Map and channel values must be allocated using the builtin function make. A variable declared with map or channel type without an initializer will be automatically initialized to nil. Calling make(map[int]int) returns a newly allocated value of type map[int]int. All rights reserved © MEP

10 Inheritance - Interface All rights reserved © MEP Where C++ provides classes, subclasses and templates, Go provides interfaces. A Go interface is similar to a C++ pure abstract class: a class with no data members, with methods which are all pure virtual. However, in Go, any type which provides the methods named in the interface may be treated as an implementation of the interface. No explicitly declared inheritance is required. A method looks like an ordinary function definition, except that it has a receiver. The receiver is similar to the this pointer in a C++ class method. type myType struct { i int } func (p *myType) get() int { return p.i } type myInterface interface { get() int; set(i int); }

11 Hello GIT All rights reserved © MEP package main import "fmt " // Package implementing formatted I/O. func main() { fmt.Printf("Hello,GIT\n") } package main import "fmt " // Package implementing formatted I/O. func main() { fmt.Printf("Hello,GIT\n") } Hello,GIT

12 An Example All rights reserved © MEP package main import "fmt " func main() { var k int = 12 var a int = 3 sum := k + a fmt.Printf(" The sum of %d and %d is %d\n", k, a, sum ) } The sum of 12 and 3 is 15

13 A call for action All rights reserved © MEP  It's early yet but promising.  A very comfortable and productive language.  Lots of documents on the web:  specification, tutorial, "Effective Go", FAQs, more  Full open-source implementations.  Want to try it?  Want to help?  Want to build libraries or tools?  http://golang.org

14 All rights reserved © MEP


Download ppt "FASTFAST All rights reserved © MEP Make programming fun again."

Similar presentations


Ads by Google