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
95
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
120
Other Decks in Programming
See All in Programming
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
3
6.7k
フロントエンド開発のためのブラウザ組み込みAI入門
masashi
7
3.5k
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
240
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
400
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
240
Android16 Migration Stories ~Building a Pattern for Android OS upgrades~
reoandroider
0
140
ソフトウェア設計の実践的な考え方
masuda220
PRO
4
650
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
910
bootcamp2025_バックエンド研修_WebAPIサーバ作成.pdf
geniee_inc
0
130
Ktorで簡単AIアプリケーション
tsukakei
0
100
モテるデスク環境
mozumasu
3
1.3k
NIKKEI Tech Talk#38
cipepser
0
230
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Six Lessons from altMBA
skipperchong
29
4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.2k
The Cult of Friendly URLs
andyhume
79
6.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
190
55k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
How to train your dragon (web standard)
notwaldorf
97
6.3k
How to Think Like a Performance Engineer
csswizardry
27
2.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
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