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
92
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
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
150
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
120
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
1k
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.8k
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
550
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
580
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
680
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
320
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
320
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
100
既存デザインを変更せずにタップ領域を広げる方法
tahia910
1
250
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
950
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Why Our Code Smells
bkeepers
PRO
337
57k
Building an army of robots
kneath
306
45k
Making Projects Easy
brettharned
116
6.3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Unsuck your backbone
ammeep
671
58k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
940
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
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