Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Golang for Rubyists
Search
Nihad Abbasov
April 13, 2019
Programming
1
67
Golang for Rubyists
Nihad Abbasov
April 13, 2019
Tweet
Share
More Decks by Nihad Abbasov
See All by Nihad Abbasov
Performance Optimization 101 for Ruby developers
narkoz
1
110
Other Decks in Programming
See All in Programming
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
730
What We Can Learn From OSS
inouehi
0
420
Let's learn code review
riofujimon
2
340
雑に思考を整理する技術と効能
konifar
60
29k
Tailwind CSSを本気でカスタマイズする方法
fsubal
13
5.3k
Fast JSX: Don't clone props object #28768
yossydev
1
100
ゆるい個人開発のススメ
kuroppe1819
10
990
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Goのmultiple errorsについて (2024年4月版)
syumai
3
870
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
130
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
200
SIMD Parallel Programming with the Vector API
josepaumard
0
180
Featured
See All Featured
Facilitating Awesome Meetings
lara
42
5.6k
Typedesign – Prime Four
hannesfritz
36
2.1k
How STYLIGHT went responsive
nonsquared
92
4.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
121
39k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
17
1.4k
Designing on Purpose - Digital PM Summit 2013
jponch
110
6.5k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
How GitHub (no longer) Works
holman
304
140k
Product Roadmaps are Hard
iamctodd
44
9.7k
Teambox: Starting and Learning
jrom
128
8.4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
244
20k
Transcript
GOLANG FOR RUBYISTS RUBY WINE, APR 13 2019
! RUBY SUX — GOLANG RULEZ!!!11 DISCLAIMER
! RUBY SUX — GOLANG RULEZ!!!11 DISCLAIMER
whoami Nihad Abbasov github.com/narkoz
[email protected]
Agenda Introduction 01 Why Golang Comparing syntax and features Additional
resources 02 03 04
None
Go is a modern, general purpose language.
Created in 2009 SECTION ONE
by Google for Google SECTION ONE
Go’s Creators • Ken Thompson (B, C, Unix, UTF-8) •
Rob Pike (Unix, UTF-8) • Robert Griesmer (V8, HotSpot, JVM)
Go Today
Rewrite from Java to Go https://twitter.com/rob_pike/status/878412416127606784
Why Golang? SECTION TWO
“Go at Google: Language Design in the Service of Software
Engineering” https://talks.golang.org/2012/splash.article SECTION TWO
Key points • must work at scale • must be
familiar, roughly C-like • must be modern
Enter Go + Fast: fast compilation like interpreted language +
Safe: strongly and statically typed and garbage collected + Easy: concise, easy to read + Modern: built in support for multi-core networked distributed applications
Popular areas where Go is used https://blog.golang.org/survey2018-results
Software written in Go https://blog.golang.org/survey2018-results
Getting started SECTION THREE
PROJECT LAYOUT https://golang.org/doc/code.html#Workspaces
HELLO WORLD package main import "fmt" func main() { fmt.Println("Hello,
World!") }
RUNNING THE CODE go build hello-world.go ./hello-world
RUNNING THE CODE go run hello-world.go
Basic syntax SECTION THREE
Keywords https://golang.org/ref/spec#Keywords The following keywords are reserved and may not
be used as identifiers.
Data types SECTION THREE
Data Types • Boolean types: true, false • Numeric types:
integers, floats • String types • Derived types: pointers, arrays, structs, functions, slices, interfaces, maps, channels
Variables SECTION THREE
VARIABLES var x float64 x = 20.0 // same as
above var x float64 = 20.0 foo := 42 var a, b, c = 3, 4, "foo" Static Declaration Dynamic Declaration Mixed Declaration
Conditionals SECTION THREE
CONDITIONALS if 7%2 == 0 { fmt.Println("7 is even") }
else { fmt.Println("7 is odd") } if/else if 8%4 == 0 { fmt.Println("8 is divisible by 4") } if statement without an else
CONDITIONALS t := time.Now() switch { case t.Hour() < 12:
fmt.Println("It’s before noon") default: fmt.Println("It’s after noon") } switch
Loops SECTION THREE
{ LOOPS for for loop until while
LOOPS i := 1 for i <= 3 { fmt.Println(i)
i = i + 1 } single condition for i := 0, i < 3; i++ { fmt.Println(i) } initial/condition/after
LOOPS for { fmt.Println("loop") break } for without a condition
Slices SECTION THREE
SLICES s := make([]string, 3) s[0] = "a" s[1] =
"b" s[2] = "c" s = append(s, "d", "e")
Maps SECTION THREE
MAPS m := map[string]int{ "foo": 1, "bar": 2 } fmt.Println(m["foo"])
Functions SECTION THREE
FUNCTIONS func FunctionName([parameter_name type]) [return_types] { // body of the
function } func plus(a int, b int) int { return a + b } sum := plus(1, 2)
FUNCTIONS func vals() (int, int) { return 3, 7 }
Exceptions SECTION THREE
EXCEPTIONS result, err:= Sqrt(-1) if err != nil { fmt.Println(err)
}
Concurrency SECTION THREE
Concurrency != Parallelism SECTION THREE https://blog.golang.org/concurrency-is-not-parallelism
Concurrency is the composition of independently executed processes, while parallelism,
is the simultaneous execution. Rob Pike
GOROUTINES func f(n int) { for i := 0; i
< 10; i++ { fmt.Println(n, ":", i) } } func main() { go f(0) var input string fmt.Scanln(&input) }
CHANNELS func main() { messages := make(chan string) go func()
{ messages <- "ping" }() msg := <-messages fmt.Println(msg) }
Is Go object oriented? SECTION THREE
STRUCTS type Person struct { name string age int }
p := Person{"John", 20} fmt.Println(p.name)
INTERFACES type Animal interface { Speak() string } type Cat
struct { } func (c Cat) Speak() string { return "Meow!" }
Resources SECTION FOUR
RESOURCES The Go Programming Language by Alan Donovan Brian Kernighan
RESOURCES List of Golang books https://github.com/dariubs/GoBooks
RESOURCES A curated list of awesome Go frameworks, libraries and
software https://github.com/avelino/awesome-go https://awesome-go.com/
RESOURCES Go Playground https://play.golang.org/ Go Tour https://tour.golang.org/
RESOURCES A weekly newsletter about the Go programming language https://golangweekly.com/
RESOURCES “Goby is an object-oriented interpreter language deeply inspired by
Ruby as well as its core implementation by 100% pure Go” https://github.com/goby-lang/goby
Thanks! THE END