SlideShare ist ein Scribd-Unternehmen logo
1 von 66
Downloaden Sie, um offline zu lesen
Java to Golang: An Intro
Ryan Dawson
Seldon
LJC
20/02/20
Outline
Why Golang?
Coming from Java
The Golang ethos
Golang features
Golang examples
Why this presentation?
I came to Go after doing Java for 10 years.
There are preconceptions you have to force yourself out of.
We can’t learn a language in a presentation. We can try to break these
preconceptions and make a revealing comparison.
Why Go?
Good concurrency features
Simplicity of core concepts
Great in-built standard libraries
Compiles to standalone binary
Fast cold start and low memory footprint
The language of Kubernetes
Golang for DevOps
Coming from Java
Packaging system very different. No maven!
Structs look like Java objects but they’re not.
No inheritance
Scoping very different
No Spring! No Spring Boot!
No Spring Boot!
But that’s how I choose which libraries to use....
I @Autowired my whole life already...
I do my best copy-pasting from Spring Boot examples
It’ll be ok
The go standard library is extensive. Includes:
- Json and yaml handling
- Http/Web server
- Templating
- Database drivers
- …
You can achieve encapsulation without Spring Beans
There’s lots of good, readable Go code out there
When in go, do as the gophers do
“If a language has too many features, you waste time choosing which ones
to use.” Rob Pike
Clear, maintainable code with low cognitive overhead
Go has a simplicity culture
Java loves design patterns.
Design patterns mean there’s more than one way.
Gophers think Java provides too much freedom, which overcomplicates.
Java Preconception: OO Won
Java thinks it is the end of history
Think C
Navigating the Ecosystem
If you search for Java webapp examples you’ll probably find lots of struts, JSF,
JSP, tomcat, jetty etc.
Spring boot provides some standardisation. You can plug things but your API into
them is pretty much the same.
For Golang, searches tend to immediately give something usable.
https://github.com/avelino/awesome-go
This is an Intro
Even short programming exercises (e.g. TDD katas) take longer than this
presentation.
We can’t learn the language here. But we can get an initial feeling for it.
Let’s start simple
Hello Random Number
Functions
Variable Initialization
If-else Checks
Exports and Packages
Modules
In the code:
import "github.com/username/packagename"
From the command-line, in the project:
go get -u github.com/username/packagename
Updates a go.mod file. The -u forces an update.
Or just go build and it automatically updates go.mod and builds the code.
That’s basically it.
Modules and versions
Reference a tag with
go get example.com/hello@v1.0.1-alpha
It can get more complex but that’s the core of it.
You can import different versions of the same dependency in your app.
Structs
Structs and Interfaces
Structs and Interfaces
Polymorphism without inheritance
No need to explicitly implement an interface or inherit in order to qualify as an
interface type
Go can be weird
Json Encoding
Json Parsing
Web Server
Channels
In Action
Weirdness
The interface casting is unusual.
More often you’d use a struct.
But it shows the flexibility as well as how different this is from jackson.
Channels and go-routines look almost too simple but they’re powerful. Sometimes
Go is chosen because of them.
Go in action
How would we do typical web CRUD apps in Go like we do in Java?
Spring Data Reminder
Spring Data Rest
Maven dependency
Exposing REST API with Spring
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findByLastName(@Param("name") String name);
}
Spring Web CRUD Example
You don’t do much directly with tomcat or hibernate. They’re abstracted. This is to
make them pluggable.
Gives a sense of magic though. With Golang you are closer to the project APIs.
Let’s see by using https://tutorialedge.net/golang/golang-orm-tutorial/
Golang In-mem DB
Main sets up handlers
List Users
Add User
Golang web crud example
https://tutorialedge.net/golang/golang-orm-tutorial/
Comparing
Spring boot version much shorter but feels more ‘magic’.
Need to know what is going on even if you don’t state it. Apps rarely stay simple.
Go version more low-level - json and db handling code explicit
Means intent is more explicit
Web CRUD is more typical of Java than Go
Testing
Mockito is heavily used in Java.
Testify in Go has similar functionality but isn’t so dominant.
Mocks in Java: Mockito
Go Testify
Learning Go
Java Spring has a whole ethos. We get so embedded we no longer notice it.
Go also wants to achieve simplicity and standardisation.
But at the language level. Without inheritance or a DI framework.
Best to think of Go and Java as different rather than ask which is better, at least
while learning.
When Go?
Lots of languages do crud web dev fine - python django, ruby, node, java, go.
Think about what other projects you’re interacting with and their APIs.
Opinion: If you really just need web dev and crud then either use what you prefer
or what you can resource for.
Further reading
Go In Action
The Go Programming Language
goroutines
https://gobyexample.com/goroutines
channels
https://gobyexample.com/channels
more testing
https://medium.com/boldly-going/unit-testing-in-go-with-ginkgo-part-1-ce6ff06eb17f
CLI-builder features
https://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177
docker, env vars and logs
https://www.callicoder.com/docker-golang-image-container-example/
K8s libraries
https://www.oreilly.com/library/view/programming-kubernetes/9781492047094/ch04.html
awesome go list
https://github.com/avelino/awesome-go
REJECTED SLIDES
SLIDES FROM HERE WILL NOT BE IN PRESENTATION
Golang for k8s
The k8s libraries are among the most used and are well-supported, along with
AWS SDK.
Go also popular for web development and CLI building (cobra).
So a good choice for a web app or CLI that interacts with low-level k8s or other
cloud infra.
No Spring Beans!
Uses of Spring Beans:
- Configurable apps + libraries (@Configuration)
- Constructing a kind of API with scoping features (@ComponentScan of
packages)
- Mock injection
Can write good apps with golang’s built-in language features.
It doesn’t have to mean any more code for library writers or library users.
Living Without Spring Beans
Config can be done with env vars and initialisation methods and params
APIs can be well-designed without beans. Exporting helps with scoping (we’ll
cover it)
Go’s built-in testing support is popular and there are frameworks such as testify
(which we’ll look at).
Living without Spring
Spring does help produce standardisation. But golang is more opinionated than
Java.
Spring is more overrideable but I’ve not found myself missing that.
You do see more code generators with go - kubebuilder, hugo, cobra. And it’s
promoted. There’s no direct equivalent of the spring boot starter.
There is a good package management system.
Stop Thinking Spring
No under the hood magic controlled by switches in go
Much more in the standard library
Learn to think go
Spring could prob be done in go but it’s not the go ethos
Project Layout and Patterns
https://github.com/golang-standards/project-layout
Pkg? Maybe that’s too much?
Links there look interesting
PROBABLY DITCH THIS SLIDE
Treasure example?
Compare http examples java and golang
Walkthrough? Atomic integer?
https://github.com/ryandawsonuk/secrets-treasurehunt
Or do something based on calling an online json to yaml service?
Or add a separate thing on goroutines and locks?
Json Parsing
https://gobyexample.com/json shows interface and casting
Web Calls
Web Calls
https://words.bighugelabs.com/api/sample/json gives some example json (more readable in a json
formatter)
https://github.com/matryer/goblueprints/blob/master/chapter4/thesaurus/bighuge.go selectively reads parts of it into
a struct
Or use https://gobyexample.com/http-clients ?
Sidenote: Type embedding not inheritance
Choosing packages
I first look at standard library, then a relevant open source project then look at
what’s popular. Others do similar.
A good reference is https://github.com/avelino/awesome-go
Upside of Go as a developer
Great k8s-related libraries
Simple basic structures, esp. concurrency
Modules are great
Standard library is great
Downsides of Go
Not everyone on modules yet and they’re kinda github-centric
At the fringes choosing libraries does get tricky
Takes some getting used to when coming from java!
Error handling is a bit verbose but that’s being looked at
Generics would be nice and are being considered

Weitere ähnliche Inhalte

Was ist angesagt?

Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in DjangoKevin Harvey
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI JoeShawn Price
 
Realtime Apps with Django
Realtime Apps with DjangoRealtime Apps with Django
Realtime Apps with DjangoRenyi Khor
 
Introduction to Groovy Monkey
Introduction to Groovy MonkeyIntroduction to Groovy Monkey
Introduction to Groovy Monkeyjervin
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC FrameworkBala Kumar
 
Getting big without getting fat, in perl
Getting big without getting fat, in perlGetting big without getting fat, in perl
Getting big without getting fat, in perlDean Hamstead
 
Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011dimakovalenko
 
Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Jorge Franco Leza
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsJames Williams
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django frameworkflapiello
 
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello ProductionZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 

Was ist angesagt? (20)

Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI Joe
 
Realtime Apps with Django
Realtime Apps with DjangoRealtime Apps with Django
Realtime Apps with Django
 
Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
 
Introduction to Groovy Monkey
Introduction to Groovy MonkeyIntroduction to Groovy Monkey
Introduction to Groovy Monkey
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Grooscript greach 2015
Grooscript greach 2015Grooscript greach 2015
Grooscript greach 2015
 
Grooscript gr8conf 2015
Grooscript gr8conf 2015Grooscript gr8conf 2015
Grooscript gr8conf 2015
 
Getting big without getting fat, in perl
Getting big without getting fat, in perlGetting big without getting fat, in perl
Getting big without getting fat, in perl
 
Grooscript greach
Grooscript greachGrooscript greach
Grooscript greach
 
Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011
 
Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
 
Dust.js
Dust.jsDust.js
Dust.js
 
Web Leaps Forward
Web Leaps ForwardWeb Leaps Forward
Web Leaps Forward
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django framework
 
Grooscript and Grails 3
Grooscript and Grails 3Grooscript and Grails 3
Grooscript and Grails 3
 
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello ProductionZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
 

Ähnlich wie Java to Golang: An Intro to Key Differences

Django and Mongoengine
Django and MongoengineDjango and Mongoengine
Django and Mongoengineaustinpublic
 
Spring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails PresentationSpring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails Presentationajevans
 
Spring boot 3g
Spring boot 3gSpring boot 3g
Spring boot 3gvasya10
 
Spring-batch Groovy y Gradle
Spring-batch Groovy y GradleSpring-batch Groovy y Gradle
Spring-batch Groovy y GradleAntonio Mas
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in DjangoLakshman Prasad
 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Max De Marzi
 
Django for Professionals Production websites with Python & Django
Django for Professionals Production websites with Python & DjangoDjango for Professionals Production websites with Python & Django
Django for Professionals Production websites with Python & Djangole980895
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyPatrick Devins
 
Modern JavaScript Talk
Modern JavaScript TalkModern JavaScript Talk
Modern JavaScript TalkDerek Binkley
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesTikal Knowledge
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 
0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdfradhianiedjan1
 

Ähnlich wie Java to Golang: An Intro to Key Differences (20)

Django and Mongoengine
Django and MongoengineDjango and Mongoengine
Django and Mongoengine
 
Spring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails PresentationSpring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails Presentation
 
Spring boot 3g
Spring boot 3gSpring boot 3g
Spring boot 3g
 
Spring-batch Groovy y Gradle
Spring-batch Groovy y GradleSpring-batch Groovy y Gradle
Spring-batch Groovy y Gradle
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1
 
Django for Professionals Production websites with Python & Django
Django for Professionals Production websites with Python & DjangoDjango for Professionals Production websites with Python & Django
Django for Professionals Production websites with Python & Django
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copy
 
Modern JavaScript Talk
Modern JavaScript TalkModern JavaScript Talk
Modern JavaScript Talk
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
React Django Presentation
React Django PresentationReact Django Presentation
React Django Presentation
 
Beginning development in go
Beginning development in goBeginning development in go
Beginning development in go
 
0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf
 
Capistrano for non-rubyist
Capistrano for non-rubyistCapistrano for non-rubyist
Capistrano for non-rubyist
 

Mehr von Mauricio (Salaboy) Salatino

Lessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsLessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsMauricio (Salaboy) Salatino
 
Building Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfBuilding Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfMauricio (Salaboy) Salatino
 
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdfKUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdfMauricio (Salaboy) Salatino
 
The Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsThe Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsMauricio (Salaboy) Salatino
 
Functions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfFunctions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfMauricio (Salaboy) Salatino
 
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022 Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022 Mauricio (Salaboy) Salatino
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Mauricio (Salaboy) Salatino
 
Knative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and UpdateKnative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and UpdateMauricio (Salaboy) Salatino
 
CDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystemCDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystemMauricio (Salaboy) Salatino
 
A Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU ValenciaA Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU ValenciaMauricio (Salaboy) Salatino
 
KCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre AbstraccionesKCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre AbstraccionesMauricio (Salaboy) Salatino
 
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingKubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingMauricio (Salaboy) Salatino
 
Cloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with KnativeCloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with KnativeMauricio (Salaboy) Salatino
 

Mehr von Mauricio (Salaboy) Salatino (20)

Devoxx UK - Platforms on top of K8s
Devoxx UK - Platforms on top of K8sDevoxx UK - Platforms on top of K8s
Devoxx UK - Platforms on top of K8s
 
WTF_is_SRE_DeveloperEnabledPlatforms.pdf
WTF_is_SRE_DeveloperEnabledPlatforms.pdfWTF_is_SRE_DeveloperEnabledPlatforms.pdf
WTF_is_SRE_DeveloperEnabledPlatforms.pdf
 
Lessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsLessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ Rejekts
 
Building Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfBuilding Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdf
 
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdfKUBEDAY - JAPAN  2022 - Building FaaS Platforms.pdf
KUBEDAY - JAPAN 2022 - Building FaaS Platforms.pdf
 
The Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsThe Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native Platforms
 
Functions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfFunctions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdf
 
JBCNConf 2022: Go vs Java (Kubernetes)
JBCNConf 2022: Go vs Java (Kubernetes)JBCNConf 2022: Go vs Java (Kubernetes)
JBCNConf 2022: Go vs Java (Kubernetes)
 
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022 Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX -  2022
Expanding Interoperability in the CD ecosystem - CDCon - Austin, TX - 2022
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`
 
KnativeCon 2022 - Knative Functions
KnativeCon 2022 - Knative FunctionsKnativeCon 2022 - Knative Functions
KnativeCon 2022 - Knative Functions
 
Knative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and UpdateKnative Maintainers KubeConEU 22 Knative Overview and Update
Knative Maintainers KubeConEU 22 Knative Overview and Update
 
CDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystemCDEventsCon Expanding Interoperability in the CD ecosystem
CDEventsCon Expanding Interoperability in the CD ecosystem
 
A Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU ValenciaA Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
A Polyglot Developer Experience on Kubernetes - KubeCon EU Valencia
 
Pave the Golden Path On Your Internal Platform
Pave the Golden Path On Your Internal PlatformPave the Golden Path On Your Internal Platform
Pave the Golden Path On Your Internal Platform
 
Knative and Spring - Bringing back the func.pdf
Knative and Spring - Bringing back the func.pdfKnative and Spring - Bringing back the func.pdf
Knative and Spring - Bringing back the func.pdf
 
KCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre AbstraccionesKCD Guatemala - Abstracciones sobre Abstracciones
KCD Guatemala - Abstracciones sobre Abstracciones
 
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingKubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
 
Cloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with KnativeCloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
Cloud Native Islamabad - Getting Closer to Continuous Delivery with Knative
 
Intro to the Cloud with Knative (Spanish)
Intro to the Cloud with Knative (Spanish) Intro to the Cloud with Knative (Spanish)
Intro to the Cloud with Knative (Spanish)
 

Kürzlich hochgeladen

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Kürzlich hochgeladen (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Java to Golang: An Intro to Key Differences

  • 1. Java to Golang: An Intro Ryan Dawson Seldon LJC 20/02/20
  • 2. Outline Why Golang? Coming from Java The Golang ethos Golang features Golang examples
  • 3. Why this presentation? I came to Go after doing Java for 10 years. There are preconceptions you have to force yourself out of. We can’t learn a language in a presentation. We can try to break these preconceptions and make a revealing comparison.
  • 4. Why Go? Good concurrency features Simplicity of core concepts Great in-built standard libraries Compiles to standalone binary Fast cold start and low memory footprint The language of Kubernetes
  • 6. Coming from Java Packaging system very different. No maven! Structs look like Java objects but they’re not. No inheritance Scoping very different No Spring! No Spring Boot!
  • 7. No Spring Boot! But that’s how I choose which libraries to use.... I @Autowired my whole life already... I do my best copy-pasting from Spring Boot examples
  • 8. It’ll be ok The go standard library is extensive. Includes: - Json and yaml handling - Http/Web server - Templating - Database drivers - … You can achieve encapsulation without Spring Beans There’s lots of good, readable Go code out there
  • 9. When in go, do as the gophers do “If a language has too many features, you waste time choosing which ones to use.” Rob Pike Clear, maintainable code with low cognitive overhead
  • 10. Go has a simplicity culture Java loves design patterns. Design patterns mean there’s more than one way. Gophers think Java provides too much freedom, which overcomplicates.
  • 11. Java Preconception: OO Won Java thinks it is the end of history
  • 13. Navigating the Ecosystem If you search for Java webapp examples you’ll probably find lots of struts, JSF, JSP, tomcat, jetty etc. Spring boot provides some standardisation. You can plug things but your API into them is pretty much the same. For Golang, searches tend to immediately give something usable. https://github.com/avelino/awesome-go
  • 14. This is an Intro Even short programming exercises (e.g. TDD katas) take longer than this presentation. We can’t learn the language here. But we can get an initial feeling for it.
  • 21. Modules In the code: import "github.com/username/packagename" From the command-line, in the project: go get -u github.com/username/packagename Updates a go.mod file. The -u forces an update. Or just go build and it automatically updates go.mod and builds the code. That’s basically it.
  • 22. Modules and versions Reference a tag with go get example.com/hello@v1.0.1-alpha It can get more complex but that’s the core of it. You can import different versions of the same dependency in your app.
  • 25. Structs and Interfaces Polymorphism without inheritance No need to explicitly implement an interface or inherit in order to qualify as an interface type
  • 26. Go can be weird
  • 31.
  • 33. Weirdness The interface casting is unusual. More often you’d use a struct. But it shows the flexibility as well as how different this is from jackson. Channels and go-routines look almost too simple but they’re powerful. Sometimes Go is chosen because of them.
  • 34. Go in action How would we do typical web CRUD apps in Go like we do in Java?
  • 37. Exposing REST API with Spring @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { List<Person> findByLastName(@Param("name") String name); }
  • 38. Spring Web CRUD Example You don’t do much directly with tomcat or hibernate. They’re abstracted. This is to make them pluggable. Gives a sense of magic though. With Golang you are closer to the project APIs. Let’s see by using https://tutorialedge.net/golang/golang-orm-tutorial/
  • 40. Main sets up handlers
  • 43. Golang web crud example https://tutorialedge.net/golang/golang-orm-tutorial/
  • 44. Comparing Spring boot version much shorter but feels more ‘magic’. Need to know what is going on even if you don’t state it. Apps rarely stay simple. Go version more low-level - json and db handling code explicit Means intent is more explicit Web CRUD is more typical of Java than Go
  • 45. Testing Mockito is heavily used in Java. Testify in Go has similar functionality but isn’t so dominant.
  • 46. Mocks in Java: Mockito
  • 48. Learning Go Java Spring has a whole ethos. We get so embedded we no longer notice it. Go also wants to achieve simplicity and standardisation. But at the language level. Without inheritance or a DI framework. Best to think of Go and Java as different rather than ask which is better, at least while learning.
  • 49. When Go? Lots of languages do crud web dev fine - python django, ruby, node, java, go. Think about what other projects you’re interacting with and their APIs. Opinion: If you really just need web dev and crud then either use what you prefer or what you can resource for.
  • 50. Further reading Go In Action The Go Programming Language goroutines https://gobyexample.com/goroutines channels https://gobyexample.com/channels more testing https://medium.com/boldly-going/unit-testing-in-go-with-ginkgo-part-1-ce6ff06eb17f CLI-builder features https://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177 docker, env vars and logs https://www.callicoder.com/docker-golang-image-container-example/ K8s libraries https://www.oreilly.com/library/view/programming-kubernetes/9781492047094/ch04.html awesome go list https://github.com/avelino/awesome-go
  • 51.
  • 52. REJECTED SLIDES SLIDES FROM HERE WILL NOT BE IN PRESENTATION
  • 53. Golang for k8s The k8s libraries are among the most used and are well-supported, along with AWS SDK. Go also popular for web development and CLI building (cobra). So a good choice for a web app or CLI that interacts with low-level k8s or other cloud infra.
  • 54. No Spring Beans! Uses of Spring Beans: - Configurable apps + libraries (@Configuration) - Constructing a kind of API with scoping features (@ComponentScan of packages) - Mock injection Can write good apps with golang’s built-in language features. It doesn’t have to mean any more code for library writers or library users.
  • 55. Living Without Spring Beans Config can be done with env vars and initialisation methods and params APIs can be well-designed without beans. Exporting helps with scoping (we’ll cover it) Go’s built-in testing support is popular and there are frameworks such as testify (which we’ll look at).
  • 56. Living without Spring Spring does help produce standardisation. But golang is more opinionated than Java. Spring is more overrideable but I’ve not found myself missing that. You do see more code generators with go - kubebuilder, hugo, cobra. And it’s promoted. There’s no direct equivalent of the spring boot starter. There is a good package management system.
  • 57. Stop Thinking Spring No under the hood magic controlled by switches in go Much more in the standard library Learn to think go Spring could prob be done in go but it’s not the go ethos
  • 58. Project Layout and Patterns https://github.com/golang-standards/project-layout Pkg? Maybe that’s too much? Links there look interesting PROBABLY DITCH THIS SLIDE
  • 59. Treasure example? Compare http examples java and golang Walkthrough? Atomic integer? https://github.com/ryandawsonuk/secrets-treasurehunt Or do something based on calling an online json to yaml service? Or add a separate thing on goroutines and locks?
  • 62. Web Calls https://words.bighugelabs.com/api/sample/json gives some example json (more readable in a json formatter) https://github.com/matryer/goblueprints/blob/master/chapter4/thesaurus/bighuge.go selectively reads parts of it into a struct Or use https://gobyexample.com/http-clients ?
  • 63. Sidenote: Type embedding not inheritance
  • 64. Choosing packages I first look at standard library, then a relevant open source project then look at what’s popular. Others do similar. A good reference is https://github.com/avelino/awesome-go
  • 65. Upside of Go as a developer Great k8s-related libraries Simple basic structures, esp. concurrency Modules are great Standard library is great
  • 66. Downsides of Go Not everyone on modules yet and they’re kinda github-centric At the fringes choosing libraries does get tricky Takes some getting used to when coming from java! Error handling is a bit verbose but that’s being looked at Generics would be nice and are being considered