SlideShare a Scribd company logo
Golang Workshop
SAGAR PANDA KABEER SHAIKH
Agenda
❖ Small talks and networking
❖ Introduction to Golang
❖ Why Golang
❖ Trends
❖ Golang Syntax & Hello World
❖ Implementing chatbot
❖ QA
Introduction
“Go will be the server language of the future.”
— Tobias Lütke,
CEO - Shopify
Creators
Created by Google Inc in 2009 by:
● Ken Thompson (B, C, UNIX, UTF-8),
● Rob Pike(UNIX, UTF-8) and
● Robert Griesmer (HotSpot, JVM)
● Procedural and imperative
● Object-oriented - Yes and No
● Compiled
● Syntax similar to C-family
● Concurrency inspired by CSP
Nature
Why they created Go?
● Frustration with existing language
● Had to choose either efficient compilation, efficient execution or ease of
programming
● Dynamic typed (Python,JavaScript): easy +ve, safety -ve, efficiency -ve
● Compiled ( C ) are fast, but difficult to work and not safe
● Interpreted (Ruby) safe but slower
● Libraries and tools cannot address issues like lightweight type system,
concurrency and garbage collection, rigid dependency specification and
so on
Go removes all obstacles
Fast: fast compilation like interpreted language
Safe: Strongly and statically typed and garbage collected
Easy: Concise , easy to read
Modern: Built in support for multi-core networked distributed applications
Why learn or switch to Golang?
Go has the cutest mascot
GO GO GO...
● Overcoming hardware limitations
● Go’s Goroutines
● Go runs directly on underlying hardware
● Easy to maintain
● Best for microservices
Overcoming hardware limitations
● 2000 - 1st P-4 processor with 1.4 GHz clock speed,
● 2004 - with 3.0GHz clock speed
● 2014 - Core i7 4790K with 4.0Ghz clock speed
● Manufacturers added multiple cores, hyper-threading technology, more
cache
● Limitations on adding more h/w, cannot rely on hardware for
performance
● Multi-core processors run multiple threads simultaneously - Go captures
concurrency
Golang workshop - Mindbowser
Golang workshop - Mindbowser
Go’s Goroutines
● Today's applications use multiple microservices which needs easy
concurrency and scalability with increase no of cores
● Modern prog lang (like Java,Python etc) - 90’s single threaded
environment
● They support multi-threading but problems with concurrent execution,
threading-locking, race conditions and deadlocks
● Creating new thread in Java is not memory efficient, 1 thread = 1mb
memory of heap size
● Golang created in 2009 under multiple core processors. 1 thread = 2Kb
Go’s Goroutines
● Growable segmented stacks - use more memory only when needed.
● Faster startup time than threads
● Come with built-in primitives to communicate safely between themselves
(channels)
● Goroutines and OS threads do not have 1:1 mapping. A single goroutine
can run on multiple threads
Gos Goroutines
Go runs directly on underlying hardware
Execution steps for VM based languages Execution steps for compiled languages
Easy to maintain
● No classes: Go has only structs instead of classes
● Does not support inheritance: Make code easy to modify. In other
languages like Java/Python, if the class ABC inherits class XYZ and you
make some changes in class XYZ, then that may produce some side
effects in other classes that inherit XYZ. By removing inheritance, Go
makes it easy to understand the code also
● No constructors
● No assertions
● No generics
● No exceptions
Easy to maintain
Best suitable for microservices
● Lightweight, very fast
● Fantastic support for concurrency, which is a powerful capability when
running across several machines and cores
● Microservice framework like go-micro or go-kit
● Pluggable architecture based on RPC - gRPC
Trends - Major Companies using Golang
Trends - % of Stack Overflow question for Go
Source: https://insights.stackoverflow.com/trends?tags=go
Trends - Most used and wanted languages in 2017
Source:
https://www.stackoverflowbusiness.com/hubfs/content/2017_Global_Developer_Hiring_Landscape.
pdf
Trends - Popularity
Source: http://redmonk.com/sogrady/2017/06/08/language-rankings-6-17/
Trends - Programming language Hall of Fame
Source: https://www.tiobe.com/tiobe-index/
Golang workshop - Mindbowser
Syntax
C Java Go
Extension .c .java .go
VM Needed Not needed JVM is there to
convert java files
to class files
Not needed
Compiler TurboC javac gc
Program
Execution
Starts from
main() function
Starts from
public static void
main(String[ ]
args)
starts from
func main() and
should be in
package main
Syntax
C Java Go
Variable
Declaration
int a; float b;
int a,b,c;
Initialization
int a=25;
char c=’a’;
int a; float b; a int
var c string
var a,b,c float
Initialization
var o,p int=34,65
k=45.67 (type of variable
auto judged by
compiler)
Shorthand notation
a:=30 (only inside
function)
Data Types bytes,short,int,long,
double,float,char,void
Primitive
bytes,short,int,long
,double,float,
boolean,char
uint, int,float32,...,
complex, byte,rune
C Java Go
Constant const int LEN=10 final int PI=3.14 const LEN int=10
Operators All operators like
Arithmetic,Logical,
Bitwise etc. are
same
All operators like
Arithmetic,Logical,
Bitwise etc. are
same
All operators like
Arithmetic,Logical,
Bitwise etc. are
same
Decision Making
Statements
(If else)
if(i>5){
flag=true
}
else{
flag=false
}
if(i>5){
flag=true
}
else{
flag=false
}
if i>5{
flag=true
}else{
flag=false
}
Syntax
C Java Go
Switch Case switch(i){
case 1: ……
break;
.
.
default:.....
break ;
}
switch(i){
case 1: ……
break;
.
.
default:.....
break ;
}
Expression switch
switch marks{
case 90: grade==’A’
case 50,60,70:grade==’C .
default: fmt.Println(“Invalid”)
}
Type switch
var x interface{}
switch x.(type){
case int:
fmt.Println(“x is int”)
default:
fmt.Println(“I don’t know”)
}
Syntax
C Java Go
For loop for(i=1;i<5;i++){
……...
}
for(i=1;i<5;i++){
…………..
}
for i:=0;i<5;i++{
………..
}
for key,val:=range
numbers{
…………..
}
While Loop while(i<10){
i++;
}
while(i<10){
i++;
}
for sum<100{
sum+=sum
}
Syntax
C Java Go
Function Declaration
int sum(int,int)
int sum(int x,int y){
……………
return
}
Calling
int add;
add=sum(10,20)
-Supports pass by
value and reference
Define method
public int sum(int
a,int b){
…………..
return
}
-Only pass by value
func sum(no int)
(int){
……
return ..
}
-Both pass by value
and reference
Function
Overloading
No Yes No
Syntax
C Java Go
Variadic Functions No printMax(10,20,30)
public static void
printMax(double…
numbers){
……...
}
func sum(num
...int) int{
…..
….
}
Ex. Println() is
implemented in
“fmt”
package
func Println(a
...interface{})(n
int,err error)
String char greet[6]={
‘h’,’e’,’l’,’l’,’o’,’0’
}
String s=new
String(“Hello”)
var
greeting=”Hello”
Syntax
C Java Go
String Functions strcpy(str1, str2)
strcat(str1,str2)
strlen(s1)............
str.length()
str.concat(str2)
str.compareTo(str2
)
String is made up
of runes. Rune is
UTF Format (A-
’65’,a-’97’)
len(str)
strings.join(str1,str
2)
Arrays Fixed size data
structure
Declaration
int array[10];
Accessing Elements
int value=array[10]
Declaration
int[ ] numbers
Creation
numbers=new
int[10]
Declaration
var number [10]int
Initialization
Var bal=[10]
int{...............}
Syntax
C Java Go
Slice There is no growable
data structure
java.util.Collection
package provides
dynamic growable
array. E.g List,Set,Map
etc
Growable data
structure
Declaration
var numbers []int
Creation
numbers=make([
]int,5,5)
5 len, 5 is capacity
append(),copy()
Default value - nil
Map There is no map data
structure in C
Key, Value pair
Map m=new
HashMap()
Map[key] value
Default value is nil
Syntax
C Java Go
Map - m.put(“Zero”,1)
put( )
get( )
ForEach to iterate
over collection and
array
var dictionary=map
[string] int
dictionary[“Zero”]=1
Create using make
var dict=make(map
[string] int)
Range -> to iterate over
slice,map
for key,val:=range values
{
……...
}
Syntax
C Java Go
Struct / Class Collection of fields and
methods
struct book{
int id;
char name[50];
char author[50];
}book;
//Access members
struct book book1;
strcpy(book1.id,400)
Java does not have
struct but have
class
class Books{
int id;
String name;
String author;
void display(){
…………...
}
}
Books b=new
Book();
b.name=”Vision”
Go have struct to
hold data in
variables.
type struct Book{
id int;
name string;
}
func(book3 *Book)
display() {
…………..
}
book1:=new(Book)
var book2 Book;
book2.name=”Go”
Syntax
C Java Go
Embedding It is like inheritance
in Java
class A {
….
}
Class B extends A
{
...
}
type Person struct{
Name string
}
func (per *Person)
speak(){
……..
}
type Mobile struct{
Person
Model String
}
Mob:=new(Mobile)
mob.Person.speak(
)
Syntax
C Java Go
Pointer Direct address of
memory location
int *a
a=&b;
NULL pointer
Always assign null
value to pointer
variable when you
don’t know exact
address to assign
int *a=NULL;
Java does not
support pointer
var a *int
var fp *float32
a=&p
NIL pointer
var *p int=nil
Syntax
C Java Go
Interface C does not have
interface concept
-Collection of only abstract
methods (from java 8 it
supports static methods
also)
-Classes implements
interface
public interface Animal{
public void eat();
public void sleep();
}
public class Monkey extends
Animal{
………..
}
-Provides method
signatures
type Shape
interface {
area() float64
}
type square struct{
side float64
}
func(sq Square)area( )
float64 {
return sq.side*sq.side
}
Same method signature
is implemented
Syntax
C Java Go
Go has empty interface which is like
object class in java. An empty
interface can hold any type of
value.
fmt.Println(a ...interface{ })
Type Casting Convert variable from
one to another data type
(type) expression
int sum=5,count=2;
Double d=(double)
sum/count
Widening
byte->short->int->float->
long->double
float=10
Narrowing
double->float->long->int-
>short->byte
int a=(float)10.40
var i int=10
var f float64=6.44
fmt.Println(float64(i))
fmt.Println(int(f))
Syntax
C Java Go
Error Handling -No direct support for error
handling
But it returns error no.
perror() and strerror() used to
display text message associated
with error no
int dividend=20;
int divisor=0;
int quotient;
if(divisor==0){
fprintf(stderr,”Divide by zero”);
exit(-1);
}
Exception Handling
-Exception is problem
arises during program
execution.
Checked/Unchecked Ex.
try{
……
}
catch(Exception ex){
……..
}
finally{
……..
}
No try/catch mechanism.
Instead it is having
defer,panic,recover
concepts.
-Provides error interface
type error interface{
Error() string
}
Normally function
returns error as last
return value. Use
errors.New() for
specifying error msg.
Syntax
C Java Go
Concurrency /
Multithreading
Doesn’t have
support.
Java have multithreading
concept for simultaneous
execution of different
tasks at same time.
We need to extends
Thread class or Runnable
interface and then
implement run( ) and write
your code
start(),run(),join(),sleep(),...
Here, we use
goroutines for
concurrent
execution.
To make function
as goroutine just
append go in front
of your function.
Two goroutines are
communicating
using channel
concept
Syntax
Thank You!
Drop us an email if you any doubts contact@mindbowser.com

More Related Content

PPT
Zapmeals: Sample Startup Pitch Deck (from SuperNova 2007)
PDF
Dropbox: $15K VC investment turned into $16.8B. Dropbox's initial pitch deck
PPTX
How to Drive Growth with Customer Success Metrics
PDF
Coinbase Seed Round Pitch Deck
PDF
10 SECRETS OF HIGHLY SUCCESSFUL CONTENT CREATORS VIDSUMMIT 2019
PDF
Facebook Pitch Deck
PDF
Business Model & Canvas (v. 2018 ita)
PDF
Strategic evaluation of eBay
Zapmeals: Sample Startup Pitch Deck (from SuperNova 2007)
Dropbox: $15K VC investment turned into $16.8B. Dropbox's initial pitch deck
How to Drive Growth with Customer Success Metrics
Coinbase Seed Round Pitch Deck
10 SECRETS OF HIGHLY SUCCESSFUL CONTENT CREATORS VIDSUMMIT 2019
Facebook Pitch Deck
Business Model & Canvas (v. 2018 ita)
Strategic evaluation of eBay

Similar to Golang workshop - Mindbowser (20)

PPTX
Introduction to go lang
PDF
Ruby is dying. What languages are cool now?
KEY
Google App Engine Java, Groovy and Gaelyk
PPT
A First Look at Google's Go Programming Language
PPT
Google's Go Programming Language - Introduction
PDF
Introduction to go, and why it's awesome
PPTX
Scaling applications with go
PDF
"Xapi-lang For declarative code generation" By James Nelson
PDF
Develop realtime web with Scala and Xitrum
PDF
Why Go Lang?
PPTX
carrow - Go bindings to Apache Arrow via C++-API
PPTX
1 java programming- introduction
PDF
Advantages of golang development services &amp; 10 most used go frameworks
PDF
Introduction To Apache Pig at WHUG
PDF
Golang
PPTX
Lab1GoBasicswithgo_foundationofgolang.pptx
PPT
Java for C++ programers
PPT
Java ppt-class_basic data types methods definitions
PPT
Java ppt-class_Introduction_class_Objects.ppt
PPTX
Go. Why it goes
Introduction to go lang
Ruby is dying. What languages are cool now?
Google App Engine Java, Groovy and Gaelyk
A First Look at Google's Go Programming Language
Google's Go Programming Language - Introduction
Introduction to go, and why it's awesome
Scaling applications with go
"Xapi-lang For declarative code generation" By James Nelson
Develop realtime web with Scala and Xitrum
Why Go Lang?
carrow - Go bindings to Apache Arrow via C++-API
1 java programming- introduction
Advantages of golang development services &amp; 10 most used go frameworks
Introduction To Apache Pig at WHUG
Golang
Lab1GoBasicswithgo_foundationofgolang.pptx
Java for C++ programers
Java ppt-class_basic data types methods definitions
Java ppt-class_Introduction_class_Objects.ppt
Go. Why it goes
Ad

More from Mindbowser Inc (20)

PPTX
Healthcare Technology Survey 2023
PPTX
Top DevOps Trends And Statistics You Need To Know In 2023
PPTX
How To Achieve Project Success With Your Outsourced Team?
PPTX
Data Science Consulting: From Idea To Deployment
PPTX
Understanding The Difference Between RPO And Staff Augmentation
PPTX
Top 5 Benefits Of IT Staff Augmentation For Modern Businesses
PPTX
How To Select The Right Software Architecture For Your Healthcare Product?
PDF
Agile Scrum Mastery: Learn How To Bring Complex Projects To life!
PDF
A Guide To Minimum Viable Architecture Points For Any Startup
PDF
Benefits and challenges of ehr
PDF
What To Choose Between - Native App And Hybrid Mobile App
PDF
7 Secret Reasons To Choose An Outsourced Agency?
PDF
How We Thrill Customers?
PDF
Benefits and Challenges of EHR
PDF
20 Tools That Any Non Tech Founder Can Use To Manage Their Tech Product Devel...
PDF
Get Ready For What's New In Insurance Technology Trends For 2021
PDF
10 top mobile app development trends to look out for in 2021
PDF
How To Ensure Quality With Automation
PDF
15 Questions To Answer Before Building Your Website
PDF
10 growth strategies for a telehealth platform
Healthcare Technology Survey 2023
Top DevOps Trends And Statistics You Need To Know In 2023
How To Achieve Project Success With Your Outsourced Team?
Data Science Consulting: From Idea To Deployment
Understanding The Difference Between RPO And Staff Augmentation
Top 5 Benefits Of IT Staff Augmentation For Modern Businesses
How To Select The Right Software Architecture For Your Healthcare Product?
Agile Scrum Mastery: Learn How To Bring Complex Projects To life!
A Guide To Minimum Viable Architecture Points For Any Startup
Benefits and challenges of ehr
What To Choose Between - Native App And Hybrid Mobile App
7 Secret Reasons To Choose An Outsourced Agency?
How We Thrill Customers?
Benefits and Challenges of EHR
20 Tools That Any Non Tech Founder Can Use To Manage Their Tech Product Devel...
Get Ready For What's New In Insurance Technology Trends For 2021
10 top mobile app development trends to look out for in 2021
How To Ensure Quality With Automation
15 Questions To Answer Before Building Your Website
10 growth strategies for a telehealth platform
Ad

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
The AUB Centre for AI in Media Proposal.docx
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm

Golang workshop - Mindbowser

  • 2. Agenda ❖ Small talks and networking ❖ Introduction to Golang ❖ Why Golang ❖ Trends ❖ Golang Syntax & Hello World ❖ Implementing chatbot ❖ QA
  • 3. Introduction “Go will be the server language of the future.” — Tobias Lütke, CEO - Shopify
  • 4. Creators Created by Google Inc in 2009 by: ● Ken Thompson (B, C, UNIX, UTF-8), ● Rob Pike(UNIX, UTF-8) and ● Robert Griesmer (HotSpot, JVM) ● Procedural and imperative ● Object-oriented - Yes and No ● Compiled ● Syntax similar to C-family ● Concurrency inspired by CSP Nature
  • 5. Why they created Go? ● Frustration with existing language ● Had to choose either efficient compilation, efficient execution or ease of programming ● Dynamic typed (Python,JavaScript): easy +ve, safety -ve, efficiency -ve ● Compiled ( C ) are fast, but difficult to work and not safe ● Interpreted (Ruby) safe but slower ● Libraries and tools cannot address issues like lightweight type system, concurrency and garbage collection, rigid dependency specification and so on
  • 6. Go removes all obstacles Fast: fast compilation like interpreted language Safe: Strongly and statically typed and garbage collected Easy: Concise , easy to read Modern: Built in support for multi-core networked distributed applications
  • 7. Why learn or switch to Golang?
  • 8. Go has the cutest mascot
  • 9. GO GO GO... ● Overcoming hardware limitations ● Go’s Goroutines ● Go runs directly on underlying hardware ● Easy to maintain ● Best for microservices
  • 10. Overcoming hardware limitations ● 2000 - 1st P-4 processor with 1.4 GHz clock speed, ● 2004 - with 3.0GHz clock speed ● 2014 - Core i7 4790K with 4.0Ghz clock speed ● Manufacturers added multiple cores, hyper-threading technology, more cache ● Limitations on adding more h/w, cannot rely on hardware for performance ● Multi-core processors run multiple threads simultaneously - Go captures concurrency
  • 13. Go’s Goroutines ● Today's applications use multiple microservices which needs easy concurrency and scalability with increase no of cores ● Modern prog lang (like Java,Python etc) - 90’s single threaded environment ● They support multi-threading but problems with concurrent execution, threading-locking, race conditions and deadlocks ● Creating new thread in Java is not memory efficient, 1 thread = 1mb memory of heap size ● Golang created in 2009 under multiple core processors. 1 thread = 2Kb
  • 14. Go’s Goroutines ● Growable segmented stacks - use more memory only when needed. ● Faster startup time than threads ● Come with built-in primitives to communicate safely between themselves (channels) ● Goroutines and OS threads do not have 1:1 mapping. A single goroutine can run on multiple threads
  • 16. Go runs directly on underlying hardware Execution steps for VM based languages Execution steps for compiled languages
  • 17. Easy to maintain ● No classes: Go has only structs instead of classes ● Does not support inheritance: Make code easy to modify. In other languages like Java/Python, if the class ABC inherits class XYZ and you make some changes in class XYZ, then that may produce some side effects in other classes that inherit XYZ. By removing inheritance, Go makes it easy to understand the code also ● No constructors ● No assertions ● No generics ● No exceptions
  • 19. Best suitable for microservices ● Lightweight, very fast ● Fantastic support for concurrency, which is a powerful capability when running across several machines and cores ● Microservice framework like go-micro or go-kit ● Pluggable architecture based on RPC - gRPC
  • 20. Trends - Major Companies using Golang
  • 21. Trends - % of Stack Overflow question for Go Source: https://insights.stackoverflow.com/trends?tags=go
  • 22. Trends - Most used and wanted languages in 2017 Source: https://www.stackoverflowbusiness.com/hubfs/content/2017_Global_Developer_Hiring_Landscape. pdf
  • 23. Trends - Popularity Source: http://redmonk.com/sogrady/2017/06/08/language-rankings-6-17/
  • 24. Trends - Programming language Hall of Fame Source: https://www.tiobe.com/tiobe-index/
  • 26. Syntax C Java Go Extension .c .java .go VM Needed Not needed JVM is there to convert java files to class files Not needed Compiler TurboC javac gc Program Execution Starts from main() function Starts from public static void main(String[ ] args) starts from func main() and should be in package main
  • 27. Syntax C Java Go Variable Declaration int a; float b; int a,b,c; Initialization int a=25; char c=’a’; int a; float b; a int var c string var a,b,c float Initialization var o,p int=34,65 k=45.67 (type of variable auto judged by compiler) Shorthand notation a:=30 (only inside function) Data Types bytes,short,int,long, double,float,char,void Primitive bytes,short,int,long ,double,float, boolean,char uint, int,float32,..., complex, byte,rune
  • 28. C Java Go Constant const int LEN=10 final int PI=3.14 const LEN int=10 Operators All operators like Arithmetic,Logical, Bitwise etc. are same All operators like Arithmetic,Logical, Bitwise etc. are same All operators like Arithmetic,Logical, Bitwise etc. are same Decision Making Statements (If else) if(i>5){ flag=true } else{ flag=false } if(i>5){ flag=true } else{ flag=false } if i>5{ flag=true }else{ flag=false } Syntax
  • 29. C Java Go Switch Case switch(i){ case 1: …… break; . . default:..... break ; } switch(i){ case 1: …… break; . . default:..... break ; } Expression switch switch marks{ case 90: grade==’A’ case 50,60,70:grade==’C . default: fmt.Println(“Invalid”) } Type switch var x interface{} switch x.(type){ case int: fmt.Println(“x is int”) default: fmt.Println(“I don’t know”) } Syntax
  • 30. C Java Go For loop for(i=1;i<5;i++){ ……... } for(i=1;i<5;i++){ ………….. } for i:=0;i<5;i++{ ……….. } for key,val:=range numbers{ ………….. } While Loop while(i<10){ i++; } while(i<10){ i++; } for sum<100{ sum+=sum } Syntax
  • 31. C Java Go Function Declaration int sum(int,int) int sum(int x,int y){ …………… return } Calling int add; add=sum(10,20) -Supports pass by value and reference Define method public int sum(int a,int b){ ………….. return } -Only pass by value func sum(no int) (int){ …… return .. } -Both pass by value and reference Function Overloading No Yes No Syntax
  • 32. C Java Go Variadic Functions No printMax(10,20,30) public static void printMax(double… numbers){ ……... } func sum(num ...int) int{ ….. …. } Ex. Println() is implemented in “fmt” package func Println(a ...interface{})(n int,err error) String char greet[6]={ ‘h’,’e’,’l’,’l’,’o’,’0’ } String s=new String(“Hello”) var greeting=”Hello” Syntax
  • 33. C Java Go String Functions strcpy(str1, str2) strcat(str1,str2) strlen(s1)............ str.length() str.concat(str2) str.compareTo(str2 ) String is made up of runes. Rune is UTF Format (A- ’65’,a-’97’) len(str) strings.join(str1,str 2) Arrays Fixed size data structure Declaration int array[10]; Accessing Elements int value=array[10] Declaration int[ ] numbers Creation numbers=new int[10] Declaration var number [10]int Initialization Var bal=[10] int{...............} Syntax
  • 34. C Java Go Slice There is no growable data structure java.util.Collection package provides dynamic growable array. E.g List,Set,Map etc Growable data structure Declaration var numbers []int Creation numbers=make([ ]int,5,5) 5 len, 5 is capacity append(),copy() Default value - nil Map There is no map data structure in C Key, Value pair Map m=new HashMap() Map[key] value Default value is nil Syntax
  • 35. C Java Go Map - m.put(“Zero”,1) put( ) get( ) ForEach to iterate over collection and array var dictionary=map [string] int dictionary[“Zero”]=1 Create using make var dict=make(map [string] int) Range -> to iterate over slice,map for key,val:=range values { ……... } Syntax
  • 36. C Java Go Struct / Class Collection of fields and methods struct book{ int id; char name[50]; char author[50]; }book; //Access members struct book book1; strcpy(book1.id,400) Java does not have struct but have class class Books{ int id; String name; String author; void display(){ …………... } } Books b=new Book(); b.name=”Vision” Go have struct to hold data in variables. type struct Book{ id int; name string; } func(book3 *Book) display() { ………….. } book1:=new(Book) var book2 Book; book2.name=”Go” Syntax
  • 37. C Java Go Embedding It is like inheritance in Java class A { …. } Class B extends A { ... } type Person struct{ Name string } func (per *Person) speak(){ …….. } type Mobile struct{ Person Model String } Mob:=new(Mobile) mob.Person.speak( ) Syntax
  • 38. C Java Go Pointer Direct address of memory location int *a a=&b; NULL pointer Always assign null value to pointer variable when you don’t know exact address to assign int *a=NULL; Java does not support pointer var a *int var fp *float32 a=&p NIL pointer var *p int=nil Syntax
  • 39. C Java Go Interface C does not have interface concept -Collection of only abstract methods (from java 8 it supports static methods also) -Classes implements interface public interface Animal{ public void eat(); public void sleep(); } public class Monkey extends Animal{ ……….. } -Provides method signatures type Shape interface { area() float64 } type square struct{ side float64 } func(sq Square)area( ) float64 { return sq.side*sq.side } Same method signature is implemented Syntax
  • 40. C Java Go Go has empty interface which is like object class in java. An empty interface can hold any type of value. fmt.Println(a ...interface{ }) Type Casting Convert variable from one to another data type (type) expression int sum=5,count=2; Double d=(double) sum/count Widening byte->short->int->float-> long->double float=10 Narrowing double->float->long->int- >short->byte int a=(float)10.40 var i int=10 var f float64=6.44 fmt.Println(float64(i)) fmt.Println(int(f)) Syntax
  • 41. C Java Go Error Handling -No direct support for error handling But it returns error no. perror() and strerror() used to display text message associated with error no int dividend=20; int divisor=0; int quotient; if(divisor==0){ fprintf(stderr,”Divide by zero”); exit(-1); } Exception Handling -Exception is problem arises during program execution. Checked/Unchecked Ex. try{ …… } catch(Exception ex){ …….. } finally{ …….. } No try/catch mechanism. Instead it is having defer,panic,recover concepts. -Provides error interface type error interface{ Error() string } Normally function returns error as last return value. Use errors.New() for specifying error msg. Syntax
  • 42. C Java Go Concurrency / Multithreading Doesn’t have support. Java have multithreading concept for simultaneous execution of different tasks at same time. We need to extends Thread class or Runnable interface and then implement run( ) and write your code start(),run(),join(),sleep(),... Here, we use goroutines for concurrent execution. To make function as goroutine just append go in front of your function. Two goroutines are communicating using channel concept Syntax
  • 43. Thank You! Drop us an email if you any doubts contact@mindbowser.com

Editor's Notes

  • #5: Procedural because procedures (functions) are stitched together to form a program. Imperative because functions are built out of statements which are generally phrased as imperative commands.
  • #16: Go takes good of both the worlds ( C family and Erlang). Easy to write concurrent and efficient to manage concurrency.
  • #21: https://github.com/golang/go/wiki/GoUsers
  • #22: https://insights.stackoverflow.com/trends?tags=go
  • #23: https://www.stackoverflowbusiness.com/hubfs/content/2017_Global_Developer_Hiring_Landscape.pdf
  • #24: http://redmonk.com/sogrady/2017/06/08/language-rankings-6-17/
  • #25: https://www.tiobe.com/tiobe-index/