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
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
170
0
Share
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
120
Go and Node.js: a comparison
nathany
1
250
Diet Hacks
nathany
2
390
Go 1.6 and HTTP/2
nathany
3
160
Upgrading Rails Redux
nathany
1
100
GopherCon recap
nathany
0
190
Go Functions
nathany
0
110
Go Types
nathany
2
140
Go Packages
nathany
2
570
Other Decks in Programming
See All in Programming
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
110
感情を設計する
ichimichi
5
1.5k
Programming with a DJ Controller — not vibe coding
m_seki
3
140
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
400
Making the RBS Parser Faster
soutaro
0
490
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
480
PHPer、Cloudflare に引っ越す
suguruooki
1
100
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
790
第3木曜LT会 #28
tinykitten
PRO
0
110
Kubernetes上でAgentを動かすための最新動向と押さえるべき概念まとめ
sotamaki0421
3
610
レガシーPHP転生 〜父がドメインエキスパートだったのでDDD+Claude Codeでチート開発します〜
panda_program
0
1k
Back to the roots of date
jinroq
0
320
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
110
Six Lessons from altMBA
skipperchong
29
4.2k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1k
First, design no harm
axbom
PRO
2
1.2k
Statistics for Hackers
jakevdp
799
230k
Thoughts on Productivity
jonyablonski
76
5.1k
Navigating Team Friction
lara
192
16k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.1k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.1k
Transcript
gophers := [4]string{"blue", "pink", "purple", "blue"}
Arrays are fixed-length planets := [8]string{ "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", } 0 1 2 3 4 5 6 7
Arrays are values planetBackup := planets // make way
for an interstellar bypass planets[2] = “" fmt.Println(planets) // [Mercury Venus Mars Jupiter Saturn Uranus Neptune] fmt.Println(planetBackup) // [Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune]
Slicing makes a window terrestrial := planets[0:4] gasGiants := planets[4:6]
iceGiants := planets[6:8] 0 1 2 3 4 5 6 7 terrestrial gasGiants iceGiants
Half-open range planets[2:3] // [Earth] < 3 • starts at
index 2 • excludes index 3
Defaults terrestrial := planets[:4] gasGiants := planets[4:6] iceGiants := planets[6:]
allPlanets := planets[:]
Making a slice // allPlanets := planets[:] planets := []string{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", }
Append to slices planets = append(planets, "Pluto") 0 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 fmt.Println(len(planets), cap(planets)) // 9 16
Append again planets = append(planets, "Eris", "Sedna") fmt.Println(len(planets), cap(planets))
// 11 16
http://blog.golang.org/go-slices-usage-and-internals https://github.com/golang/go/wiki/SliceTricks More reading