Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Goの標準ライブラリに学ぶジェネリクス
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
tychy
June 15, 2023
Programming
840
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Goの標準ライブラリに学ぶジェネリクス
https://gihyo.jp/article/2023/05/tukinami-go-07?summary
tychy
June 15, 2023
Transcript
15 slides
1 Goの標準ライブラリに学ぶジェネリクス Ryu Yamada Mercari.go #22 June 15, 2023
2 自己紹介 • Ryu Yamada ◦ https://github.com/tychy ◦ https://twitter.com/tychy16 •
2022年 4 月入社 ◦ Partner Platform Team • Backend Engineer
3 ジェネリクス使ってますか? Agenda timeパッケージでの利用例 slices/mapsパッケージでの利用例 標準ライブラリにジェネリクスを導入する難しさ 02 03 04 01
4 ジェネリクス使ってますか? Go1.18でリリースされた待望の機能 実際使ってますか? • 使い所が難しい... • 今のところユースケースがない... • 気はなってはいる...
🤔 標準ライブラリでの使い方を見てみよう 💡
5 timeパッケージでの利用例 • atoiをジェネリクスを使って実装 • []byteとstringの変換がいらない 日付と時刻の操作を行うパッケージ
6 timeパッケージでのご利益 • パフォーマンスの向上 • 可読性と簡潔性の向上 • atoiをジェネリクスを使って実装 • []byteとstringの変換がいらない
https://github.com/golang/go/commit/72c58f b77192f7d17d87663c943360a48aae11dc MarshalJSONを高速化
7 出来ないこと
8 メソッドではジェネリクスは利用できない メソッドでジェネリクスは利用できない これはダメ
9 関数として定義するしかない 👍 ジェネリクスを使いたいなら 関数に切り出す必要がある
10 slices/mapsパッケージ • Go1.21で追加予定 • sliceやmapに対する操作を提供
11 標準ライブラリ特有の難しさ math.Abs/Min/Maxやlist.List等にもジェネリクス入れない の? 使いどころはわかってきた 💡 🤔 list.Listを例に考えてみる
12 標準ライブラリ特有の難しさ list.Listはinterface{}型を利用して実装されている
13 標準ライブラリ特有の難しさ ジェネリクスを使って実装し直すと後方互換性が失われる 型が違うのでコンパイルできない
14 考えられる解決策 特に標準パッケージではジェネリクスへの移行は容易ではない 解決策も議論されている • ジェネリクスを使って実装されたV2パッケージを用意 • ジェネリクス用の関数を分けて定義する
15 ジェネリクスの現在地とこれから 標準ライブラリではジェネリクスの利用が始まっている • 今回紹介した例以外にもatomic.Pointer型で利用されている • slices/mapsが標準パッケージに取り込まれた ジェネリクスを活用し始める良いタイミング!
More Decks by tychy
See All by tychy
データベースロギングの多様性
tychy
0
350
Other Decks in Programming
See All in Programming
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
320
AI Augmentation Techniques with Liberty
ivargrimstad
1
520
SODA - FACT BOOK(EN)
sodainc
1
260
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
6.1k
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
380
Debian JP Projectのサーバー構成
uwabami
1
140
LLM 101
dalinaum
0
510
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
180
Crash Auto Pipelines
veronikapj
1
440
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
250
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
Featured
See All Featured
How to make the Groovebox
asonas
2
2.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.5k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
320
Paper Plane
katiecoart
PRO
6
55k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
380
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
630
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k