As presented at OSCON 2014.
The Go programming language has emerged as a favorite tool of DevOps and cloud practitioners alike. In many ways, Go is more famous for what it doesn’t include than what it does, and co-author Rob Pike has said that Go represents a “less is more” approach to language design.
The Cloud Foundry engineering teams have steadily increased their use of Go for building components, starting with the Router, and progressing through Loggregator, the CLI, and more recently the Health Manager. As a “recovering-Java-developer-turned-DevOps-junkie” focused on helping our customers and community succeed with Cloud Foundry, it became very clear to me that I needed to add Go to my knowledge portfolio.
This talk will introduce Go and its distinctives to Java developers looking to add Go to their toolkits. We’ll cover Go vs. Java in terms of:
* type systems
* modularity
* programming idioms
* object-oriented constructs
* concurrency
This presentation was given as a Workshop at OSCON 2014.
New to Go? This tutorial will give developers an introduction and practical
experience in building applications with the Go language. Gopher Steve Francia,
Author of [Hugo](http://hugo.spf13.com),
[Cobra](http://github.com/spf13/cobra), and many other popular Go packages
breaks it down step by step as you build your own full featured Go application.
Starting with an introduction to the Go language. He then reviews the fantastic
go tools available. With our environment ready we will learn by doing. The
remainder of the time will be dedicated to building a working go web and cli
application. Through our application development experience we will introduce
key features, libraries and best practices of using Go.
This tutorial is designed with developers in mind. Prior experience with any of the
following languages: ruby, perl, java, c#, javascript, php, node.js, or python
is preferred. We will be using the MongoDB database as a backend for our
application.
We will be using/learning a variety of libraries including:
* bytes and strings
* templates
* net/http
* io, fmt, errors
* cobra
* mgo
* Gin
* Go.Rice
* Cobra
* Viper
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Steven Francia
Object Oriented (OO) programming has dominated software engineering for the last two decades. The paradigm built on powerful concepts such as Encapsulation, Inheritance, and Polymoprhism has been internalized by the majority of software engineers. Although Go is not OO in the strict sense, we can continue to leverage the skills we’ve honed as OO engineers to come up with simple and solid designs.
Gopher Steve Francia, Author of
[Hugo](http://hugo.spf13.com), [Cobra](http://github.com/spf13/cobra), and many
other popular Go packages makes these difficult concepts accessible for everyone.
If you’re a OO programmer, especially one with a background with dynamic languages and are curious about go then this talk is for you. We will cover everything you need to know to leverage your existing skills and quickly start coding in go including:
How to use our Object Oriented programming fundamentals in go
Static and pseudo dynamic typing in go
Building fluent interfaces in go
Using go interfaces and duck typing to simplify architecture
Common mistakes made by those coming to go from other OO languages (Ruby, Python, Javascript, etc.),
Principles of good design in go.
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
Slides for Brian Bulkowski's talk about Golang performance:
microbenchmarks, profilers, and a war story about optimizing the Aerospike Database Go client.
http://www.meetup.com/Go-lang-Developers-NYC/events/216650022/
How to write a well-behaved Python command line applicationgjcross
Tutorial #1 from PyCon AU 2012
Python is a fantastic scripting language. It is easy to hack up quick scripts for all sorts of problems - without a lot more effort, that hack can become a robust, easily maintained command line application that your users love.
This tutorial covers how to write useful, well-behaved command line applications that are a joy to use:
* Easily process command line options
* Write a script that can be used interactively or as a filter
* Display help to the user
* Gracefully handle and report errors, to the user and the shell
* Trap and process signals in a robust manner
* Create an easily configured application
* Use a range of the Python standard library modules for easier command line scripting
* Test your application
* Set up the supporting files that any well-behaved application should have, eg. a man page
* How to package your application for other people to use
This tutorial will assume a very basic knowledge of Python and some familiarity with the command line environment of your choice.
7 Common mistakes in Go and when to avoid themSteven Francia
I've spent the past two years developing some of the most popular libraries and applications written in Go. I've also made a lot of mistakes along the way. Recognizing that "The only real mistake is the one from which we learn nothing. -John Powell", I would like to share with you the mistakes that I have made over my journey with Go and how you can avoid them.
This presentation was given as a Workshop at OSCON 2014.
New to Go? This tutorial will give developers an introduction and practical
experience in building applications with the Go language. Gopher Steve Francia,
Author of [Hugo](http://hugo.spf13.com),
[Cobra](http://github.com/spf13/cobra), and many other popular Go packages
breaks it down step by step as you build your own full featured Go application.
Starting with an introduction to the Go language. He then reviews the fantastic
go tools available. With our environment ready we will learn by doing. The
remainder of the time will be dedicated to building a working go web and cli
application. Through our application development experience we will introduce
key features, libraries and best practices of using Go.
This tutorial is designed with developers in mind. Prior experience with any of the
following languages: ruby, perl, java, c#, javascript, php, node.js, or python
is preferred. We will be using the MongoDB database as a backend for our
application.
We will be using/learning a variety of libraries including:
* bytes and strings
* templates
* net/http
* io, fmt, errors
* cobra
* mgo
* Gin
* Go.Rice
* Cobra
* Viper
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Steven Francia
Object Oriented (OO) programming has dominated software engineering for the last two decades. The paradigm built on powerful concepts such as Encapsulation, Inheritance, and Polymoprhism has been internalized by the majority of software engineers. Although Go is not OO in the strict sense, we can continue to leverage the skills we’ve honed as OO engineers to come up with simple and solid designs.
Gopher Steve Francia, Author of
[Hugo](http://hugo.spf13.com), [Cobra](http://github.com/spf13/cobra), and many
other popular Go packages makes these difficult concepts accessible for everyone.
If you’re a OO programmer, especially one with a background with dynamic languages and are curious about go then this talk is for you. We will cover everything you need to know to leverage your existing skills and quickly start coding in go including:
How to use our Object Oriented programming fundamentals in go
Static and pseudo dynamic typing in go
Building fluent interfaces in go
Using go interfaces and duck typing to simplify architecture
Common mistakes made by those coming to go from other OO languages (Ruby, Python, Javascript, etc.),
Principles of good design in go.
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
Slides for Brian Bulkowski's talk about Golang performance:
microbenchmarks, profilers, and a war story about optimizing the Aerospike Database Go client.
http://www.meetup.com/Go-lang-Developers-NYC/events/216650022/
How to write a well-behaved Python command line applicationgjcross
Tutorial #1 from PyCon AU 2012
Python is a fantastic scripting language. It is easy to hack up quick scripts for all sorts of problems - without a lot more effort, that hack can become a robust, easily maintained command line application that your users love.
This tutorial covers how to write useful, well-behaved command line applications that are a joy to use:
* Easily process command line options
* Write a script that can be used interactively or as a filter
* Display help to the user
* Gracefully handle and report errors, to the user and the shell
* Trap and process signals in a robust manner
* Create an easily configured application
* Use a range of the Python standard library modules for easier command line scripting
* Test your application
* Set up the supporting files that any well-behaved application should have, eg. a man page
* How to package your application for other people to use
This tutorial will assume a very basic knowledge of Python and some familiarity with the command line environment of your choice.
7 Common mistakes in Go and when to avoid themSteven Francia
I've spent the past two years developing some of the most popular libraries and applications written in Go. I've also made a lot of mistakes along the way. Recognizing that "The only real mistake is the one from which we learn nothing. -John Powell", I would like to share with you the mistakes that I have made over my journey with Go and how you can avoid them.
Given at GopherFest 2015. This is an updated version of the talk I gave in NYC Nov 14 at GothamGo.
“We need to think about failure differently. Most people think mistakes are a necessary evil. Mistakes aren't a necessary evil, they aren't evil at all. They are an inevitable consequence of doing something new and as such should be seen as valuable. “ - Ed Catmull
As Go is a "new" programming language we are all experimenting and learning how to write better Go. While most presentations focus on the destination, this presentation focuses on the journey of learning Go and the mistakes I personally made while developing Hugo, Cobra, Viper, Afero & Docker.
Golang basics for Java developers - Part 1Robert Stern
A short overview of Golang with Java comparison.
Part 1 of the series "Microservice development with Golang".
Contains hints and example links for potential Gophers
An Introduction to Groovy for Java DevelopersKostas Saidis
An introduction to Groovy for Java developers with real-life examples that present how Groovy helped us win the 2nd prize in the Open Public Data Hackathon 2014 (http://www.ydmed.gov.gr/hackathon/)
Infinum android talks_10_getting groovy on androidInfinum
Groovy is a dynamic language similar to Python, Ruby, Pearl and Smalltalk. Since it compiles to Java bytecode it can be used to write Android applications as well. We’ll demonstrate how to setup a Groovy Android application project, show the advantages, disadvantages and provide some code examples.
https://www.youtube.com/watch?v=9yxj9bxQ9H4
Dart is a new language for the web, enabling you to write JavaScript on a secure and manageable way. No need to worry about "JavaScript: The bad parts".
This presentation concentrates on the developer experience converting from the Java based GWT to Dart.
This is an interactive PowerPoint presentation I made for my seminar at my workplace. It talks and illustrates how the JavaScript engine works when executing code. It also contains a step-by-step animation which demonstrates the usage of the JavaScript event loop.
Feel free to use and refer content. Copyrights reserved.
Apache Groovy: the language and the ecosystemKostas Saidis
An overview of the Groovy language and its awesome ecosystem, advocating Groovy as the language of choice for (a) Java developers that want to dive into dynamic languages or (b) for Javascript, Ruby or Python developers that want to dive into the Java platform.
The presentation was given at the 9th FOSSCOMM (16-17 April 2016) organized by the Software Libre Sociecy of the University of Piraues.
JavaCro 2016 - From Java to Groovy: Adventure Time!Iván López Martín
Groovy is a dynamic language for the JVM and the natural evolution for a Java developer because its flat learning curve. If you want to know why developing with Groovy is an Adventure Time, this is your talk. You'll learn with examples the main characteristics that make Groovy a powerful and versatile language: dynamic typing, closures, lists and maps handling, power asserts, builders, metaprogramming, scripting, DSL's, AST transformations,... and many more.I can guarantee you that after the talk you'll want to learn more about Groovy and use it in your day at work.
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
TypeScript lets you write JavaScript the way you really want to Its a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source. Enjoy writing JavaScript.
At an event of the Java User Group Switzerland on June 3, 2015 in Zürich Netcetera's CEO Andrej Vckovski presented the modern developing system Go and compared it with Java.
Given at GopherFest 2015. This is an updated version of the talk I gave in NYC Nov 14 at GothamGo.
“We need to think about failure differently. Most people think mistakes are a necessary evil. Mistakes aren't a necessary evil, they aren't evil at all. They are an inevitable consequence of doing something new and as such should be seen as valuable. “ - Ed Catmull
As Go is a "new" programming language we are all experimenting and learning how to write better Go. While most presentations focus on the destination, this presentation focuses on the journey of learning Go and the mistakes I personally made while developing Hugo, Cobra, Viper, Afero & Docker.
Golang basics for Java developers - Part 1Robert Stern
A short overview of Golang with Java comparison.
Part 1 of the series "Microservice development with Golang".
Contains hints and example links for potential Gophers
An Introduction to Groovy for Java DevelopersKostas Saidis
An introduction to Groovy for Java developers with real-life examples that present how Groovy helped us win the 2nd prize in the Open Public Data Hackathon 2014 (http://www.ydmed.gov.gr/hackathon/)
Infinum android talks_10_getting groovy on androidInfinum
Groovy is a dynamic language similar to Python, Ruby, Pearl and Smalltalk. Since it compiles to Java bytecode it can be used to write Android applications as well. We’ll demonstrate how to setup a Groovy Android application project, show the advantages, disadvantages and provide some code examples.
https://www.youtube.com/watch?v=9yxj9bxQ9H4
Dart is a new language for the web, enabling you to write JavaScript on a secure and manageable way. No need to worry about "JavaScript: The bad parts".
This presentation concentrates on the developer experience converting from the Java based GWT to Dart.
This is an interactive PowerPoint presentation I made for my seminar at my workplace. It talks and illustrates how the JavaScript engine works when executing code. It also contains a step-by-step animation which demonstrates the usage of the JavaScript event loop.
Feel free to use and refer content. Copyrights reserved.
Apache Groovy: the language and the ecosystemKostas Saidis
An overview of the Groovy language and its awesome ecosystem, advocating Groovy as the language of choice for (a) Java developers that want to dive into dynamic languages or (b) for Javascript, Ruby or Python developers that want to dive into the Java platform.
The presentation was given at the 9th FOSSCOMM (16-17 April 2016) organized by the Software Libre Sociecy of the University of Piraues.
JavaCro 2016 - From Java to Groovy: Adventure Time!Iván López Martín
Groovy is a dynamic language for the JVM and the natural evolution for a Java developer because its flat learning curve. If you want to know why developing with Groovy is an Adventure Time, this is your talk. You'll learn with examples the main characteristics that make Groovy a powerful and versatile language: dynamic typing, closures, lists and maps handling, power asserts, builders, metaprogramming, scripting, DSL's, AST transformations,... and many more.I can guarantee you that after the talk you'll want to learn more about Groovy and use it in your day at work.
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
TypeScript lets you write JavaScript the way you really want to Its a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source. Enjoy writing JavaScript.
At an event of the Java User Group Switzerland on June 3, 2015 in Zürich Netcetera's CEO Andrej Vckovski presented the modern developing system Go and compared it with Java.
Everyone have their own reasons to love or hate a programming language. In this opinionated talk I'll share what makes Go special for me, and what I miss the most whenever I get to write code in a different language.
Expect to hear not only about features but why they matter, and how they make Go unique and special.
---
Presented at the Golang Brno meetup #1, on May 17th, 2016.
This presentation will give developers an introduction and practical experience
of using MongoDB with the Go language. MongoDB Chief Developer Advocate &
Gopher Steve Francia presents plainly what you need to know about using MongoDB
with Go.
As an emerging language Go is able to start fresh without years of relational database dependencies. Application and library developers are able to build applications using the excellent Mgo MongoDB driver and the reliable go sql package for relational database. Find out why some people claim Go and MongoDB are a “pair made in heaven” and “the best database driver they’ve ever used” in this talk by Gustavo Niemeyer, the author of the mgo driver, and Steve Francia, the drivers team lead at MongoDB Inc.
We will cover:
Connecting to MongoDB in various configurations
Performing basic operations in Mgo
Marshaling data to and from MongoDB
Asynchronous & Concurrent operations
Pre-fetching batches for seamless performance
Using GridFS
How MongoDB uses Mgo internally
HTTP 2.0 is supposed to be the next big thing for the web, after the overwhelming success of HTTP 1.1.
A dive into the HTTP 2.0 protocol, what is the status of its specification, what features does it offer over HTTP 1.1, and how websites can benefit (in speed and money) from it.
An exploration of what does it take to write HTTP 2.0 applications in the Java platform, what plans there are to support it in JDK 9 and which Servlet Containers are already offering HTTP 2.0 support.
Go 1.10 Release Party, featuring what's new in Go 1.10 and a few deep dives into how Go works.
Presented at the PDX Go Meetup on April 24th, 2018.
https://www.meetup.com/PDX-Go/events/248938586/
eact is a library for building HTML user interfaces. It is the "view" in a Model-View-Controller application. Created by the UI wizards at Facebook, top websites like Instagram, Netflix, Airbnb, Bleacher Report and Feedly use it. React is the 6th most starred project on GitHub and grows more popular every day.
In this two-day workshop, we will introduce you to React. On the first day, we will work through a series of increasingly more complicated tutorial exercises. Along the way, we will explain concepts like JSX, immutability, statefulness, one-way data flow, components, and virtual DOM.
With the basics out of the way, we will spend the second-day building a complex application which will put React through its paces and give us a chance to explore most of its features. Then we will learn how to think in React. We will show you how to go from design to components to working application. We will wrap the weekend with a quick preview of React Native, which allows you to use your React skills to create cross-platform mobile apps.
He will start you at the beginning and cover prerequisites; setting up your development environment first. Afterward, you will use npm to install react-native-cli. The CLI is our go to tool. We use it to create and deploy our app.
Next, you will explore the code. React Native will look familiar to all React developers since it is React. The main difference between React on the browser and a mobile device is the lack of a DOM. We take a look a many of the different UI components that are available.
With React Native you have access to all of the devices hardware features like cameras, GPS, fingerprint reader and more. So we'll show some JavaScript code samples demonstrating it. We will wrap up the evening by deploying our app to both iOS and Android devices and with tips on getting ready for both devices stores.
All software architectures have to deal with stress. Its simply the way the world works! Stressors come from multiple directions, including changes in the marketplace, business models, and customer demand, as well as infrastructure failures, improper or unexpected inputs, and bugs. As software architects, one of our jobs is to create solutions that meet both business and quality requirements while appropriately handling stress. We typically approach stressors by trying to create solutions that are robust. Robust systems can continue functioning properly in the presence of internal and external challenges, but they also have one or more breaking points. When we pass a robust system's known threshold for a particular type of stress, it will fail. When a system encounters an unknown unknown challenge, it will usually not be robust! Recent years have seen new approaches, including resilient, antifragile, and evolutionary architectures. All of these approaches emphasize the notion of adapting to changing conditions in order to not only survive stress but sometimes to benefit from it. In this presentation, we'll examine the theory and practice behind these architectural approaches.
Cloud Foundry: The Best Place to Run MicroservicesMatt Stine
A magical tour through the Industrial Revolution, Complex Adaptive Systems, and Turtles All the Way Down, with shout outs to Cloud Foundry, BOSH, and Spring Boot.
Lattice: A Cloud-Native Platform for Your Spring ApplicationsMatt Stine
As presented at SpringOne2GX 2015 in Washington, DC.
Lattice is a cloud-native application platform that enables you to run your applications in containers like Docker, on your local machine via Vagrant. Lattice includes features like:
Cluster scheduling
HTTP load balancing
Log aggregation
Health management
Lattice does this by packaging a subset of the components found in the Cloud Foundry elastic runtime. The result is an open, single-tenant environment suitable for rapid application development, similar to Kubernetes and Mesos Applications developed using Lattice should migrate unchanged to full Cloud Foundry deployments.
Lattice can be used by Spring developers to spin up powerful micro-cloud environments on their desktops, and can be useful for developing and testing cloud-native application architectures. Lattice already has deep integration with Spring Cloud and Spring XD, and you’ll have the opportunity to see deep dives into both at this year’s SpringOne 2GX. This session will introduce the basics:
Installing Lattice
Lattice’s Architecture
How Lattice Differs from Cloud Foundry
How to Package and Run Your Spring Apps on Lattice
Microservice architectures have generated quite a bit of hype in recent months, and practitioners across our industry have vigorously debated the definition, purpose, and effectiveness of these architectures.
In this session, Matt Stine will cut through the Microservices hype and examine some very practical considerations:
• Not an End in Themselves: Microservices are really all about helping us achieve continuous delivery
• Systems over Services: Microservices are less about the services themselves and more about the systems we can assemble using them. Boilerplate patterns for configuration, integration, and fault tolerance are keys.
• Operationalized Architecture: Microservices aren’t a free lunch. You have to pay for them with strong DevOps sauce.
• It’s About the Data: Bounded contexts with API’s are great until you need to ask really big questions. How do we effectively wrangle all of the data at once?
Along the way, we’ll see how open source technology efforts such as Cloud Foundry, Spring Cloud, Netflix OSS, Spring XD, and Hadoop can help us with many of these considerations.
Deploying Microservices to Cloud FoundryMatt Stine
As presented at Cloud Foundry Summit 2015 in Santa Clara, CA.
Now that you have Cloud Foundry, what are you going to do with it?
This presentation will show using Spring Cloud on Cloud Foundry to quickly leverage common microservice patterns, including distributed configuration management, service discovery, intelligent routing, load balancing, and fault tolerance.
Using Spring Cloud on Cloud Foundry, developers can take advantage of the cloud native microservice architectures pioneered by those building the web at places like Twitter, LinkedIn, and Netflix. In many cases they can do so running the same code with Spring Cloud wrapping the same battle-tested open source components those companies are running in production.
Cloud Foundry Diego: Modular and Extensible Substructure for MicroservicesMatt Stine
The Diego project was originally conceived as a rewrite of the Droplet Execution Agent (DEA) component of the Cloud Foundry elastic runtime, the component responsible for scheduling, starting, stopping, and scaling applications in Linux containers. Since Diego’s inception, this development effort has been guided by core principles such as simplicity, loose coupling, high cohesion, separation of concerns, and seeking the right abstractions.
These guiding principles have resulted in an extremely modular platform that provides a welcome home for your microservices. Microservices are loosely coupled, independently deployable applications whose individual scopes are guided by the concept of bounded contexts. Martin Fowler has described well the operational maturity required to employ microservices architectures, memorably stating “you must be this tall to ride the microservices ride,” with the capability to do rapid deployment and basic monitoring. Diego’s opinionated automation and health checking provide a great platform for operating microservices. At the same time, this platform has clean abstractions that support useful extension points.
In this presentation we'll explore the Diego architecture, highlight Diego’s role as the new core of the Cloud Foundry elastic runtime, and illustrated how Diego is being used as a component in other platforms such as Lattice and Spring XD. We'll also look at how Diego's abstractions provided an easy road to adding alternative backends for other platforms like core Windows/.NET support to Cloud Foundry. Finally, we'll discover how Diego's abstractions are providing the Spring Cloud project with a clear road to providing tighter integration between the Netflix OSS stack of services and Cloud Foundry, with a goal of enabling support for polyglot cloud-native application architectures.
Building Distributed Systems with Netflix OSS and Spring CloudMatt Stine
As presented at: http://www.meetup.com/Pivotal-Open-Source-Hub/events/219264521/
With the advent of microservice and cloud-native application architectures, building distributed systems is becoming increasingly common for the enterprise Java developer. Fortunately many of the innovators in the space, including Twitter, LinkedIn, and Netflix, have embraced the JVM as they’ve built increasingly complex systems, with Netflix open-sourcing much of its toolkit for constructing these systems at NetflixOSS.
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems. Many of these patterns are provided via wrapping the battle-tested components found at NetflixOSS.
Cloud Foundry and Microservices: A Mutualistic Symbiotic RelationshipMatt Stine
As delivered to the Cloud Foundry Summit 2014 in San Francisco, CA:
With businesses built around software now disrupting multiple industries that appeared to have stable leaders, the need has emerged for enterprises to create "software factories" built around the following principles:
* Streaming customer feedback directly into rapid, iterative cycles of application development
* Horizontally scaling applications to meet user demand
* Compatibility with an enormous diversity of clients, with mobility (smartphones, tablets, etc.) taking the lead
* Continuous delivery of value, shrinking the cycle time from concept to cash
Infrastructure has taken the lead in adapting to meet these needs with the move to the cloud, and Platform as a Service (PaaS) has raised the level of abstraction to a focus on an ecosystem of applications and services. However, most applications are still developed as if we're living in the previous generation of both business and infrastructure: the monolithic application. Microservices - small, loosely coupled applications that follow the Unix philosophy of "doing one thing well" - represent the application development side of enabling rapid, iterative development, horizontal scale, polyglot clients, and continuous delivery. They also enable us to scale application development and eliminate long term commitments to a single technology stack.
While microservices are simple, they are certainly not easy. It's recently been said that "microservices are not a free lunch". Interestingly enough, if you look at the concerns expressed here about microservices, you'll find that they are exactly the challenges that a PaaS is intended to address. So while microservices do not necessarily imply cloud (and vice versa), there is in fact a symbiotic relationship between the two, with each approach somehow compensating for the limitations of the other, much like the practices of eXtreme Programming.
1. A Recovering
Java Developer Learns to Go
Matt Stine (@mstine)
Cloud Foundry Platform Engineer at Pivotal
matt.stine@gmail.com
http://www.mattstine.com
OFFICE HOURS
Wednesday, 2:30 - 3:10 PM
Expo Hall (Table A)
4. CF Architecture - January 2013
DEA Pool
Router
Cloud Controller
BOSH Director BOSH Agent
UAA/Login Servers Health Manager
Service Broker Node(s)
Messaging (NATS)
CLI Client
Ruby
Java/Spring
Go
5. CF Architecture - January 2014
Ruby
Java/Spring
Go
Loggregator
DEA Pool (Diego - Coming soon!)
Router
Cloud Controller
BOSH Director BOSH Agent
UAA/Login Servers Health Manager
Service Broker Node(s)
Messaging (NATS)
CLI Client
7. • Mike Gehard: “Go Within Cloud Foundry”
https://www.youtube.com/watch?v=d5aHr8VGU-8
• Onsi Fakhouri: “Diego: Re-envisioning the Elastic Runtime”
https://www.youtube.com/watch?v=1OkmVTFhfLY
Go in Cloud Foundry
8. ✓ Hello World
✓ Why Go?
✓ Contrasts with Java:
- Features and Idioms
- Packaging / Modularity
- Types / OOP / Interfaces
- Concurrency
Agenda
9. package main
!
import (
"fmt"
)
!
func main() {
fmt.Println("Hello World")
}
Hello World
All code goes
in a package.
Give access to
exported
stuff from other
packages.
Function definition,
main() is entrypoint.
Call an exported function!
11. Iron Triangle of Language Design
EfficientCompilation
Ease of Programming
EfficientExecution
Systems
Programming
12. • 2007-09-21: Go invented at Google by Robert Griesemer, Rob Pike, and
Ken Thompson
• 2009-11-10: Go released as OSS
• 2012-03-28: Go 1.0 is Released
A History Lesson
13. Software Engineering in the LARGE
http://talks.golang.org/2012/splash.article
“Go is a programming language designed by Google to help solve
Google's problems, and Google has big problems.”
14. Software Engineering in the LARGE
http://talks.golang.org/2012/splash.article
“Go is a programming language designed by Google to help solve
Google's problems, and Google has big problems.”
15. ✓ Safety and efficiency of a
statically-typed, compiled language
✓ Productivity and feel of a dynamic,
interpreted language
✓ Address modern compute environments:
- Multicore Processors
- Networked Systems
- Massive Computational Clusters
- Web Programming Model
Goals
23. Closures
func main() {
nextInt := intSeq()
!
fmt.Println(nextInt())
fmt.Println(nextInt())
fmt.Println(nextInt())
!
newInts := intSeq()
fmt.Println(newInts())
}
GBE
Captures its own value for i.
Increments own value of i.
Captures the value of i again!
And increments it.
24. Where’s my java.util.List? Slices
s := make([]string, 3)
fmt.Println("emp:", s)
!
s[0] = "a"
s[1] = "b"
s[2] = "c"
fmt.Println("set:", s)
fmt.Println("get:", s[2])
!
s = append(s, "d")
s = append(s, "e", "f")
fmt.Println("apd:", s)
GBE
Create an empty slice of strings
(zero-valued).
Set value at index.
Get value at index.
Append function (not mutate in-place!).
25. Where’s my java.util.List? Slices
c := make([]string, len(s))
copy(c, s)
fmt.Println("cpy:", c)
!
l := s[2:5]
fmt.Println("sl1:", l)
!
l = s[:5]
fmt.Println("sl2:", l)
!
t := []string{"g", "h", "i"}
fmt.Println("dcl:", t)
GBE
Length function.
Copy function.
Slicing function:
index 2 (inclusive)
to index 5 (exclusive).
Slicing function:
index 0 (inclusive)
to index 5 (exclusive).
Slice literals!
26. Where’s my java.util.Map? Maps
m := make(map[string]int)
!
m["k1"] = 7
m["k2"] = 13
!
fmt.Println("map:", m)
!
v1 := m["k1"]
fmt.Println("v1: ", v1)
!
fmt.Println("len:", len(m))
Create an empty map of string ! int.
Put values.
Get value.
Length function.
GBE
27. Where’s my java.util.Map? Maps
delete(m, "k2")
fmt.Println("map:", m)
!
_, prs := m["k2"]
fmt.Println("prs:", prs)
!
n := map[string]int{"foo": 1, "bar": 2}
fmt.Println("map:", n)
Delete function.
Optional second return indicating “presence.”
Map literals!
GBE
28. Looping with Range
nums := []int{2, 3, 4}
sum := 0
for _, num := range nums {
sum += num
}
fmt.Println("sum:", sum)
!
for i, num := range nums {
if num == 3 {
fmt.Println("index:", i)
}
}
!
kvs := map[string]string{"a": "apple", "b": "banana"}
for k, v := range kvs {
fmt.Printf("%s -> %sn", k, v)
}
Discard first (index),
sum second (value).
Keep both returns!
With maps, first = key,
second = value.
GBE
29. We don’t need no stinkin’ exceptions…
func f1(arg int) (int, error) {
if arg == 42 {
return -1, errors.New("can't work with 42")
}
return arg + 3, nil
}
!
func main() {
for _, i := range []int{7, 42} {
if r, e := f1(i); e != nil {
fmt.Println("f1 failed:", e)
} else {
fmt.Println("f1 worked:", r)
}
}
}
Conventional: last return is error.
Makes an error with the provided message.
Return nil if there was no error.
Idiomatic inline
error check.
GBE
34. • Every class in a package
• Import classes explicitly
- import java.util.Map
• Import all classes in a package
- import java.util.*
• Statically import class static members:
- import static java.lang.Math.PI
- import static java.lang.Math.*
Java Packaging
35. • All types and functions belong to a package.
• Every source file must declare its package.
• Import packages to gain access to exported members.
Go Packaging
36. • public - any class in same package, or any importing class in a different
package, can see
• default (“package private”) - any class in same package can see
• protected - any class in same package, or any subclass in a different
package, can see
• private - no class other than this can see
• Scope indicated by prefixing name at declaration time.
Java Scoping
37. • exported - any code in an importing file can see
- exported names start with uppercase letter
- func Copy(src *[]byte, dest *[]byte)
• non-exported - only code in the same package can see
- non-exported names start with _ or lowercase letter
- func copy(src *[]byte, dest *[]byte)
- func _Copy(src *[]byte, dest *[]byte)
Go Scoping
38. • Conventional correspondence to directory paths (e.g. com.ms.foo
should be at src/com/ms/foo) - tools expect this!
• Package paths do not have to be unique at compile or runtime (first
dependency found/loaded wins!)
• Conventional correspondence to URL of author (e.g. my domain is
www.mattstine.com, so my packages names start with com.mattstine) -
but no actual relationship to source code location!
Java Naming
39. • Conventional correspondence to directory paths (e.g. github.com/go-martini/
martini should be at src/github.com/go-martini/martini) - tools expect this!
• Package paths MUST BE UNIQUE across a $GOPATH.
• Package names do not have to be unique.
• Referring to imported names must be qualified by package name (e.g. sql.DB not just DB)…
can locally alias (e.g. import dbstuff “database/sql”)
• Conventional correspondence to URL of code location (e.g. import http://github.com/
joefitzgerald/cfenv as import “github.com/joefitzgerald/cfenv").
• Can “go get” remote packages - supports Git, SVN, Mercurial, Bazaar.
Go Naming
40. • Java admits:
- circular package dependencies
- dead imports
• Go rejects:
- circular package dependencies
- dead imports
Miscellany
45. structs FTW
type Point struct {
X, Y float64
}
Define a type.
Give it a name.
This type is a struct.
(you can actually define others!)
Add stuff!
(upcase exports apply here too!)
46. Methods are Functions!
func (p Point) Translate(xDist float64, yDist float64) Point {
return Point{p.X + xDist, p.Y + yDist}
}
Receiver argument!
Can define methods on pointers or values.
47. composition FTW
type Point struct {
X, Y float64
}
!
const (
BLUE = iota
RED = iota
GREEN = iota
)
!
type ColorPoint struct {
Point Point
Color int
}
Define an enumerated constant
(closest to Java enum).
A ColorPoint has-a Point!
48. • I have Points.
• I have ColorPoints.
• ColorPoints are like Points, but they are not Points.
• But I want to compute the euclidean distance between them.
• What to do?
Problem
49.
50. Interfaces Group Behaviors
type Positioner interface {
Coordinates() Point
}
!
type Distancer interface {
DistanceTo(p Positioner) float64
}
51. It’s all about satisfaction…
Java = explicit
!
Go = implicit
59. • Parallelism = leveraging simultaneous execution of work to perform
many things at once. Limited to number of processors/cores you have.
• Concurrency = composition of work to manage many things at once. No
theoretical limit.
• Rob Pike: “Concurrency is Not Parallelism”
http://www.youtube.com/watch?v=cN_DpYBzKso
Concurrency vs Parallelism
60. • Java
- Threads
- OS managed
- Share address space with other threads in same process
• Go
- Goroutines
- user-space managed by language runtime
- multiplexed onto pool of OS threads
Parallelism - How?
61. • Java
- Shared memory
- Locking
• Go
- Can share memory (see http://golang.org/pkg/sync)
- But there is a better way!
Synchronization?
63. Goroutines
func f(from string) {
for i := 0; i < 3; i++ {
fmt.Println(from, ":", i)
}
}
!
func main() {
f("direct")
!
go f("goroutine")
!
go func(msg string) {
fmt.Println(msg)
}("going")
} GBE
Synchronous
Asynchronous
Asynchronous
and Anonymous
64. Channels
func main() {
messages := make(chan string)
!
go func() { messages <- "ping" }()
!
msg := <-messages
fmt.Println(msg)
}
GBE
Create a new channel.
Sending
Receiving
65. Channel Buffering
func main() {
messages := make(chan string, 2)
!
messages <- "buffered"
messages <- "channel"
!
fmt.Println(<-messages)
fmt.Println(<-messages)
}
GBE
Make a channel that will
buffer two values.
Send twice
Receive twice
66. Channel Synchronization
func worker(done chan bool) {
fmt.Print("working...")
time.Sleep(time.Second)
fmt.Println("done")
done <- true
}
!
func main() {
done := make(chan bool, 1)
go worker(done)
<-done
} GBE
Notify receive that I’m done.
Run worker on a
goroutine, pass “done”
channel.
Block until msg
received!
67. Select
c1 := make(chan string)
c2 := make(chan string)
!
go func() {
time.Sleep(time.Second * 1)
c1 <- "one"
}()
go func() {
time.Sleep(time.Second * 2)
c2 <- "two"
}()
GBE
Create two channels.
Create two goroutines; each
sends message to different channel.
68. Select
for i := 0; i < 2; i++ {
select {
case msg1 := <-c1:
fmt.Println("received", msg1)
case msg2 := <-c2:
fmt.Println("received", msg2)
}
}
GBE
Await both messages
simultaneously!
Print each as it arrives!
69. Closing Channels
jobs := make(chan int, 5)
done := make(chan bool)
!
go func() {
for {
j, more := <-jobs
if more {
fmt.Println("received job", j)
} else {
fmt.Println("received all jobs")
done <- true
return
}
}
}()
GBE
Job channel for sending work.
Done channel to indicate
all work complete.
Receive jobs - more will be
false if jobs is closed.
If no more jobs, say that I’m done!
70. Closing Channels
for j := 1; j <= 3; j++ {
jobs <- j
fmt.Println("sent job", j)
}
close(jobs)
fmt.Println("sent all jobs")
!
<-done
GBE
Send the jobs to the worker.
Close the jobs channel.
Block until the worker is finished.
71. Range Over Channels
func main() {
queue := make(chan string, 2)
queue <- "one"
queue <- "two"
close(queue)
!
for elem := range queue {
fmt.Println(elem)
}
}
GBE
Pull messages off channel
for each iteration of the loop.
72. • Features and Idioms
• Packaging / Modularity
• Types / OOP / Interfaces
• Concurrency
Contrasts with Java
73. Thank You!!!
Matt Stine (@mstine)
Cloud Foundry Platform Engineer at Pivotal
matt.stine@gmail.com
http://www.mattstine.com
OFFICE HOURS
Wednesday, 2:30 - 3:10 PM
Expo Hall (Table A)
74. Code samples marked “GBE” at https://gobyexample.com are by Mark McGranaghan and are Creative Commons Attribution 3.0
Unported licensed (http://creativecommons.org/licenses/by/3.0).
!
The Go Gopher logo was created by Renee French and is Creative Commons Attribution 3.0 Unported licensed (http://
creativecommons.org/licenses/by/3.0).
!
The Java Duke logo is BSD licensed (http://opensource.org/licenses/bsd-license.php).