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
94
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
AIと私たちの学習の変化を考える - Claude Codeの学習モードを例に
azukiazusa1
11
4.4k
複雑なフォームに立ち向かう Next.js の技術選定
macchiitaka
2
230
Zendeskのチケットを Amazon Bedrockで 解析した
ryokosuge
3
320
より安全で効率的な Go コードへ: Protocol Buffers Opaque API の導入
shwatanap
2
760
Deep Dive into Kotlin Flow
jmatsu
1
370
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.5k
Kiroで始めるAI-DLC
kaonash
2
630
print("Hello, World")
eddie
2
530
Laravel Boost 超入門
fire_arlo
3
220
RDoc meets YARD
okuramasafumi
4
170
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
550
@Environment(\.keyPath)那么好我不允许你们不知道! / atEnvironment keyPath is so good and you should know it!
lovee
0
130
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
3k
For a Future-Friendly Web
brad_frost
180
9.9k
Writing Fast Ruby
sferik
628
62k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
The Art of Programming - Codeland 2020
erikaheidi
56
13k
Music & Morning Musume
bryan
46
6.8k
A designer walks into a library…
pauljervisheath
207
24k
How to Ace a Technical Interview
jacobian
279
23k
Making Projects Easy
brettharned
117
6.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
580
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
810
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