go vs java

35
Go vs Java

Upload: adam-jedro

Post on 21-Jan-2017

81 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Go vs java

Go vs Java

Page 2: Go vs java

About meJava developer

during the day

Golang hacker by night

Hackathon enthusiast

[email protected]

github.com/jakon89

linkedin.com/in/adamjedro

Page 3: Go vs java

Go?

Page 4: Go vs java
Page 5: Go vs java
Page 6: Go vs java

similaritiesGC

Fast compiler

Influenced by C

Compiled, statically typed

Support for concurrency by default

Focused on server-side programming

Page 7: Go vs java

however...No VM

Statically linked binaries

Go does not have generics

Debuggers are still poor compared to Java debuggers

Ecosystem is tiny...

…but it’s growing rapidly

Page 8: Go vs java

Tools overview● IDE

● Dependency management

● Built-in test support

● go fmt

● go vet

● New Relic

Page 9: Go vs java

Dependency management$ go get github.com/jakon89/scribeGO

Supported repositories:

git

svn

hg

bzr

Page 10: Go vs java

before go fmt

Page 11: Go vs java

after go fmt

Page 12: Go vs java
Page 13: Go vs java

Test coverage

Page 14: Go vs java

go vetVet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string,

Unreachable code

Copying locks (Locks passed by value)

Build tags (Badly formed or misplaced +build tags)

Boolean conditions (Mistakes involving boolean operators)

Unused exported(public) fields of struct

Page 15: Go vs java

What’s new for Java devs?● No classes/exceptions/annotations/constructors

● defer

● Multiple return values

● Type inference, errors as values, access modifiers, C&ASM integration...

Page 16: Go vs java

InterfacesAll data types that implement these methods satisfy this interface implicitly; there is no implements declaration. That said, interface satisfaction is statically checked at compile time so despite this decoupling interfaces are

type-safe.

Page 17: Go vs java
Page 18: Go vs java
Page 19: Go vs java

DeferA defer statement pushes a function call onto a list.

The list of saved calls is executed after the surrounding function returns. Defer is commonly used

to simplify functions that perform various clean-up actions.

Page 20: Go vs java
Page 21: Go vs java
Page 22: Go vs java

Multiple return values

Page 23: Go vs java
Page 24: Go vs java

Cross platform supportJava is really cross platform - write once, run anywhere but...

Page 25: Go vs java

Cross compilationset target OS and architecture

run go build…

...here you go

Page 26: Go vs java

Per {OS, architecture} code

OR

Page 27: Go vs java

Goroutines vs Threads

Page 28: Go vs java

Goroutines vs Threads● Lightweight abstraction over threads

● Managed by runtime(Scheduler) not by kernel

● Not uncommon to see hundreds of thousands of them

● There are well defined constraints when Scheduler yields to another goroutine:

○ select statement

○ sending/receiving value to/from a channel

○ System call

○ time.Sleep()

○ runtime.Gosched()

○ function call

Page 29: Go vs java

ChannelsChannels are the pipes that connect concurrent

goroutines

You can send values into channels from one goroutine and receive those values in another goroutine

Page 30: Go vs java

Example!

Page 31: Go vs java
Page 32: Go vs java
Page 33: Go vs java
Page 34: Go vs java

Questions?

Page 35: Go vs java

Thanks!