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
0
130
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Tweet
Share
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
97
Go and Node.js: a comparison
nathany
1
180
Diet Hacks
nathany
2
350
Go 1.6 and HTTP/2
nathany
3
120
Upgrading Rails Redux
nathany
1
86
GopherCon recap
nathany
0
160
Go Functions
nathany
0
95
Go Types
nathany
2
130
Go Packages
nathany
2
530
Other Decks in Programming
See All in Programming
AHC 044 混合整数計画ソルバー解法
kiri8128
0
310
goにおける コネクションプールの仕組み を軽く掘って見た
aronokuyama
0
150
Devin , 正しい付き合い方と使い方 / Living and Working with Devin
yukinagae
3
760
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
560
海外のアプリで見かけたかっこいいTransitionを真似てみる
shogotakasaki
1
140
AtCoder Heuristic First-step Vol.1 講義スライド
terryu16
3
1.1k
PHPによる"非"構造化プログラミング入門 -本当に熱いスパゲティコードを求めて- #phperkaigi
o0h
PRO
0
1.2k
令和トラベルにおけるコンテンツ生成AIアプリケーション開発の実践
ippo012
1
270
CRE Meetup!ユーザー信頼性を支えるエンジニアリング実践例の発表資料です
tmnb
0
520
国漢文混用体からHolloまで
minhee
1
120
Coding Experience Cpp vs Csharp - meetup app osaka@9
harukasao
0
550
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
140
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Thoughts on Productivity
jonyablonski
69
4.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
118
51k
RailsConf 2023
tenderlove
29
1k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
How to Think Like a Performance Engineer
csswizardry
22
1.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
7
620
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
500
Writing Fast Ruby
sferik
628
61k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
30
1.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