Go1

1,418 views
1,250 views

Published on

itz a ppt on Go programming language

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,418
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
69
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Go1

  1. 1. GO PROGRAMMING LANGUAGE Technical seminar on P.VIvek REG NO. 0801209401 CSE-B
  2. 2. <ul><li>Go is a </li></ul><ul><li>New </li></ul><ul><li>Experimental </li></ul><ul><li>Concurrent </li></ul><ul><li>Garbage-Collected </li></ul><ul><li>Systems Language. </li></ul>
  3. 3. Why a new language? <ul><li>Go fast! </li></ul><ul><li>Make programming fun again. </li></ul><ul><li>No new major systems language in a decade. But much has changed: - sprawling libraries & dependency chains - dominance of networking - client/server focus - massive clusters - the rise of multi-core CPUs </li></ul><ul><li>Major systems languages were not designed with all these factors in mind. </li></ul>
  4. 4. Features <ul><li>The most important features of Go are </li></ul><ul><li>the feel of a dynamic language with the safety of a static type system. </li></ul><ul><li>compile to machine language so it runs fast. </li></ul><ul><li>real run-time that supports GC, concurrency. </li></ul><ul><li>lightweight, flexible type system. </li></ul><ul><li>has methods but not a </li></ul><ul><li>conventional object-oriented </li></ul><ul><li>language. </li></ul>
  5. 5. Compiled <ul><li>Go is a compiled language. At the moment there are two compilers. </li></ul><ul><li>  Gccgo is a Go compiler that uses the GCC back end. There is also a suite of compilers with different (and odd) names for each architecture: 6g for the 64-bit x86, 8g for the 32-bit x86, and more. </li></ul><ul><li>These compilers run </li></ul><ul><li>significantly faster but </li></ul><ul><li>generate less efficient code </li></ul><ul><li>than gccgo. </li></ul>
  6. 6. Similarity <ul><li>Go is having a similar language structure as of C. </li></ul><ul><li>Declarations are introduced by a keyword (var, </li></ul><ul><li>const, type, func) and look reversed compared to C. Examples are </li></ul><ul><li> var i int </li></ul><ul><li>const PI = 22/7 </li></ul>
  7. 7. The “:=“short declaration <ul><li>Within functions (only), declarations of the form var v = value can be shortened to v := value (Another reason for the name/type reversal.) </li></ul><ul><li>The type is that of the value (for ideal numbers, get int or float, accordingly.) </li></ul><ul><li>a, b, c, d := 1, 2.0, &quot;three&quot;, FOUR </li></ul><ul><li>These are used a lot and are </li></ul><ul><li>available in places such as for </li></ul><ul><li> loop initializers . </li></ul>
  8. 8. ZERO <ul><li>All memory in Go is initialized. All variables are initialized upon execution of their declaration. </li></ul><ul><li>Without an initializing expression, the &quot;zero value&quot; of the type is used. </li></ul><ul><li>The loop </li></ul><ul><li>for i := 0; i < 5; i++ </li></ul><ul><li>{ </li></ul><ul><li>var v int; </li></ul><ul><li>fmt.Printf(&quot;%dn&quot;, v); </li></ul><ul><li>v = 5 </li></ul><ul><li> } </li></ul><ul><li>will print 0, 0, 0, 0, 0. </li></ul><ul><li>The zero value depends on the type: </li></ul><ul><li> integer 0, </li></ul><ul><li>floating point 0.0, </li></ul><ul><li> false, empty string, nil pointer, zeroed struct, </li></ul><ul><li> etc. </li></ul>
  9. 9. SCOPE <ul><li>Within a package, all global variables, functions, types, and constants are visible from all the package's source files. </li></ul><ul><li>For clients (importers) of the package, names must be upper case to be visible: global variables, functions, types, constants, plus methods and structure fields for global variables and types. </li></ul><ul><li>const hello = &quot;you smell&quot; // package visible </li></ul><ul><li>const Hello = &quot;you smell nice&quot; // globally visible </li></ul><ul><li>const _Bye = &quot;stinko!&quot; // </li></ul><ul><li> _ is not upper </li></ul><ul><li>Very different from C/C++: </li></ul><ul><li> no extern, static, private, public. </li></ul>
  10. 10. SLICE <ul><li>A slice is a reference to a section of an array. </li></ul><ul><li>Slices are used much more often than plain arrays. A slice is very cheap. </li></ul><ul><li>A slice type looks like an array type without a size: </li></ul><ul><li> var a [] int </li></ul><ul><li>Create a slice by &quot;slicing&quot; an array or slice: </li></ul><ul><li>a = ar[7:9]; </li></ul><ul><li>Valid indexes of a will be 0, 1 </li></ul><ul><li> and len(a)==2. </li></ul>
  11. 11. MAPs <ul><li>Maps are another reference type. They are declared like this: </li></ul><ul><li>var m map[string] float </li></ul><ul><li>This declares a map indexed with key type string and value type float. It is analogous to the C++ </li></ul><ul><li>type *map<string,float> (note the *). </li></ul><ul><li>On a map, len() returns the number of keys. </li></ul>
  12. 12. INTERFACE <ul><li>The word &quot;interface&quot; is a bit overloaded in Go: </li></ul><ul><li>There is the concept of an interface, and there is an interface type, and then there are values of that type. First, the concept. </li></ul><ul><li>Definition: </li></ul><ul><li>An interface is a set of methods. An interface type is a specification of an interface, a set of methods implemented by some other types. </li></ul><ul><li>Here's a simple one, with only one method: </li></ul><ul><li>type AbsInterface interface </li></ul><ul><li> { </li></ul><ul><li>Abs() float // receiver is implied </li></ul><ul><li>} </li></ul>
  13. 13. CONCURRENCY <ul><li>A goroutine is a Go function or method executing concurrently in the same address space as other goroutines. </li></ul><ul><li>A running program consists of one or more goroutines. </li></ul><ul><li>It's not the same as a thread, coroutine, process, etc. It's a goroutine. </li></ul>
  14. 14. GOROUTINES <ul><li>Goroutines are cheap. </li></ul><ul><li>Goroutines exit by returning from their toplevel function, or just falling off the end. Or they can call runtime.Goexit(), although that's rarely necessary. </li></ul><ul><li>Goroutines can run concurrently on different processors, sharing memory. </li></ul>
  15. 15. GOROUTINES <ul><li>Goroutines are multiplexed as needed onto system threads. When a goroutine executes a blocking system call, no other goroutine is blocked. </li></ul><ul><li>We will do the same for CPU-bound goroutines at some point, but for now, if you want user-level parallelism you must set </li></ul><ul><li>$GOMAXPROCS. or call runtime.GOMAXPROCS(n). </li></ul><ul><li>GOMAXPROCS tells the runtime scheduler how many non-syscall-blocked goroutines </li></ul><ul><li>to run at once. </li></ul>
  16. 16. CHANNELS <ul><li>Unless two goroutines can communicate, they can't coordinate. </li></ul><ul><li>Go has a type called a channel that provides communication and synchronization capabilities. </li></ul><ul><li>It also has special control structures that build on channels to make </li></ul><ul><li>concurrent programming </li></ul><ul><li>easy. </li></ul>
  17. 17. Example Program <ul><li>package main </li></ul><ul><li>import &quot;fmt&quot; </li></ul><ul><li>func main() </li></ul><ul><li>{ </li></ul><ul><li>fmt.Print(&quot;Hello,n&quot;) </li></ul><ul><li>} </li></ul>
  18. 18. CONCLUSION <ul><li>It's early yet but promising. </li></ul><ul><li>A very comfortable and productive language. </li></ul><ul><li>Lots of documents on the web: specification, tutorial, &quot;Effective Go&quot;, FAQs, more.Full open-source implementations. </li></ul><ul><li>Want to try it?Want to help?Want to build libraries or tools? </li></ul><ul><li>http://golang.org </li></ul>
  19. 19. Any Queries??

×