go vs java
TRANSCRIPT
Go vs Java
About meJava developer
during the day
Golang hacker by night
Hackathon enthusiast
github.com/jakon89
linkedin.com/in/adamjedro
Go?
similaritiesGC
Fast compiler
Influenced by C
Compiled, statically typed
Support for concurrency by default
Focused on server-side programming
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
Tools overview● IDE
● Dependency management
● Built-in test support
● go fmt
● go vet
● New Relic
Dependency management$ go get github.com/jakon89/scribeGO
Supported repositories:
git
svn
hg
bzr
before go fmt
after go fmt
Test coverage
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
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...
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.
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.
Multiple return values
Cross platform supportJava is really cross platform - write once, run anywhere but...
Cross compilationset target OS and architecture
run go build…
...here you go
Per {OS, architecture} code
OR
Goroutines vs Threads
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
ChannelsChannels are the pipes that connect concurrent
goroutines
You can send values into channels from one goroutine and receive those values in another goroutine
Example!
Questions?
Thanks!