Go for Java Developers

Similar documents
Introduzione a Go e RPC in Go

Go Cheat Sheet. Operators. Go in a Nutshell. Declarations. Basic Syntax. Hello World. Functions. Comparison. Arithmetic. Credits


The Go Programming Language. Frank Roberts

developed ~2007 by Robert Griesemer, Rob Pike, Ken Thompson open source

Go Forth and Code. Jonathan Gertig. CSC 415: Programing Languages. Dr. Lyle

Go Tutorial. To do. A brief, gentle intro to Go. Next Networking. q Today

Issue with Implementing PrimeSieve() in Go

Lecture Overview Methods and Interfaces Methods review Interfaces Example: using the sort interface Anonymous fields in structs

Go Tutorial. Arjun Roy CSE 223B, Spring 2017

go get my/vulnerabilities Green threads are not eco friendly threads

understanding

Pierce Ch. 3, 8, 11, 15. Type Systems

Go on NetBSD (and pkgsrc!) A modern systems programming language 23 March Benny Siegert Google Switzerland; The NetBSD Foundation

Go Language September 2016

GO IDIOMATIC CONVENTIONS EXPLAINED IN COLOR

Distributed Systems. 02r. Go Programming. Paul Krzyzanowski. TA: Yuanzhen Gu. Rutgers University. Fall 2015

Lecture 4: Golang Programming. Lecturer: Prof. Zichen Xu

THE GO PROGRAMMING LANGUAGE CHARACTERISTICS AND CAPABILITIES

Jython. An introduction by Thinh Le

Let s Go! Akim D le, Etienne Renault, Roland Levillain. June 8, TYLA Let s Go! June 8, / 58

The Awesomeness of Go. Igor Lankin DevFest Karlsruhe, Nov 2016

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

GO MOCK TEST GO MOCK TEST I

2 rd class Department of Programming. OOP with Java Programming

Introduction to the Go Programming Language

COMP-520 GoLite Tutorial

Go Concurrent Programming. QCon2018 Beijing

GO SHORT INTERVIEW QUESTIONS EXPLAINED IN COLOR

Go Programming. Russ Cox and Rob Pike May 20, 2010

Don t let data Go astray

Rheinisch-Westfälische Technische Hochschule Aachen. Lehrstuhl für Datenmanagement und -exploration Prof. Dr. T. Seidl. Proseminar.

Introduction to Swift. Dr. Sarah Abraham

COMP 202 Java in one week

Using the Go Programming Language in Practice

Computer Components. Software{ User Programs. Operating System. Hardware

Cut. it s not just for Google. Eleanor McHugh.

William Kennedy. Brian Ketelsen Erik St. Martin Steve Francia FOREWORD BY MANNING WITH

Arrays and Strings

The current topic: Python. Announcements. Python. Python

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Motivations History Principles Language Gommunity Success stories Conclusion. Let s Go! A brief introduction to Google s new language.

The Go Programming Language. Part 3

Summary of Go Syntax /

New Parallel Programming Languages for Optimization Research

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Pointers, Dynamic Data, and Reference Types

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

Titan: A System Programming Language made for Lua

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

Don t Go Java! Edition 2019

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Introduce C# as Object Oriented programming language. Explain, tokens,

Go Circuit: Distributing the Go Language and Runtime. Petar Maymounkov

Tranquility Publications. Web Edition MAC

LECTURE 18. Control Flow

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Static Deadlock Detection for Go by Global Session Graph Synthesis. Nicholas Ng & Nobuko Yoshida Department of Computing Imperial College London

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

OCaml Data CMSC 330: Organization of Programming Languages. User Defined Types. Variation: Shapes in Java

CS112 Lecture: Primitive Types, Operators, Strings

Arrays/Slices Store Lists of Variables

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

6.096 Introduction to C++ January (IAP) 2009

Final CSE 131B Spring 2004

Lectures 5-6: Introduction to C

func findbestfold(seq string, energyfunction func(fold)float64)) Fold {

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

CS 61C: Great Ideas in Computer Architecture Introduction to C

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Future Web App Technologies

COMP520 - GoLite Type Checking Specification

CS 33. Introduction to C. Part 4. CS33 Intro to Computer Systems IV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Advanced Systems Programming

C# and Java. C# and Java are both modern object-oriented languages

Functions & Variables !

STRUCTURING OF PROGRAM

Introduction to Programming Using Java (98-388)

SWIFT! init(title: String) { self.title = title } // required initializer w/ named parameter

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

COMP520 - GoLite Type Checking Specification

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Getting started with Java

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

Lecture 9: Lists. Lists store lists of variables. Declaring variables that hold lists. Carl Kingsford, , Fall 2015

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

PIC 20A The Basics of Java

Using DPDK with Go. Takanari Hayama Technology Consulting Company IGEL Co.,Ltd.

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

GO - QUICK GUIDE GO - OVERVIEW

5) Attacker causes damage Different to gaining control. For example, the attacker might quit after gaining control.

Chapter 1 Getting Started

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Transcription:

Go for Java Developers Stoyan Rachev May 26-27 16, Sofia 1

Agenda Introduction Variables and Control Flow Types and Data Structures Functions Methods and Interfaces Concurrency Conclusion 2

What is Go? Go is an open source programming language originally from Google that makes it easy to build simple, reliable, and efficient software. 3

Why Go? Answer to the challenges of scale at Google Increasingly popular (RedMonk, Tiobe) 4

Why Go for Java Developers? Learning new languages makes us better programmers Better choice than Java in some situations Contribute or integrate with existing Go projects 5

Go and Java - Similarities C-style Imperative Compiled Statically typed Object-oriented Cross-platform Garbage collection Memory safety Type assertions Reflection 6

Go and Java - Differences No VM Syntax differences Built-in strings, arrays, and maps Type inference Closures Concurrency No classes No inheritance No exceptions No annotations No generics 7

Why So Different? Language design in the service of software engineering Familiar, yet modern High performance, compile and runtime Balance between complexity and convenience Emphasis on automated tools Less is exponentially more 8

Example: Hello, world 9

Variables and Constants // Java int x; String s = "Hello, world!"; public static final double PI = 3.14; // Go var x int s := "Hello, world!" const Pi = 3.14 10

Control Flow - for for i { < = n 0; { i < n; i++ {... 11

Control Flow - if if x < := limit math.pow(a, { n); x < limit {... else {... 12

Control Flow - switch switch lang {:= ui.ask(); lang { case "java": getlanguage():... case "go":... default:... switch true { {... 13

Basic Types and Pointers var s string var r rune var b boolean Go type int8 int16 int32 int64 float32 float64 Java type byte short int long float double var i int var p *string = &s 14

Arrays and Slices var a [2]string a[0], a[1] = "java", "go" var s []string = a[:] s := []string{"java", "go" s var:= s make([]string, 0) s = append(s, "java") 15

Maps m := make(map[string]int) m["java"], m["go"] = 1, 2 m := map[string]int{"java": 1, "go": 2 r, = ok m["go"] := m["ruby"] // ok is false delete(m, "go") 16

Structs type Point struct { X int Y int p := Point{1, &Point{1 2, 2 p.y = 3 17

Example: Meters to feet converter 18

Functions // Java public static int sum(int a, int b) { return a + b; // Go func Sum(a int, b int) int { return a + b 19

Error Handling public static int f() throws Exception { // Java... throw MyException("...");... return 1 func f() (int, error) { // Go... return 0, fmt.errorf("...")... return 1, nil 20

Error Handling Checking for Errors n, err := f() if err!= nil {... // Use n... 21

Closures func fibonacci() func() int { x, y := 0, 1 return func() int { x, y = x + y, x return x f := fibonacci() for i := 0; i < 10; i++ { fmt.println(f()) 22

defer resp, err := http.get(url) if err!= nil {... defer resp.body.close() 23

Methods type Stack struct { data []string func (s *Stack) Push(x string) { s.data = append(s.data, x) s := NewStack() s.push("hello, world!") 24

Interfaces func Fprintf(w io.writer, format string, args...interface{) (int, error) type Writer interface { Write(p []byte) (int, error) 25

Interfaces - Satisfaction type NopWriter struct { func (w *NopWriter) Write(p []byte) (int, error) return len(p), nil var w NopWriter fmt.fprintf(&w, "Hello, world!") 26

Example: Word Count 27

Go Concurrency Don't communicate by sharing memory, share memory by communicating. 28

Goroutines func say(s string) { fmt.println(s) go say("hi") say("there") 29

Channels ch := make(chan int) // create channel ch <- x // send x = <-ch // receive and assign <-ch // receive and discard close(ch) // close channel 30

select select { case <-ch1: // receive... case x := <-ch2: // receive and assign... case ch3 <- y: // send... default:... 31

Pipelines numbers := make(chan int) go func(int n) { // generator for i := 0; i < n; i++ { numbers <- i close(numbers) (10) for x := range numbers { // printer fmt.println(x) 32

Example: Pipelines 33

Tools go run go build go install go test go get gofmt goimports godep 34

Where to Go from Here? Go Web site, https://golang.org A Tour of Go, https://tour.golang.org Go Docu, https://golang.org/doc/ Go FAQ, https://golang.org/doc/faq The Go Programming Language, by A. Donovan and B. Kernighan 35

Final Words Go is similar to Java, yet different Go is simple, elegant, and efficient Go is worth giving a try! 36

THANK YOU :) You can find me at: @stoyanr stoyanr@gmail.com Stoyan Rachev May 26-27 16, Sofia 37