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でのレシーバーとnilの関係 / Receiver and nil relationshi...
Search
Kentaro Kawano
July 26, 2019
Programming
0
460
Goでのレシーバーとnilの関係 / Receiver and nil relationship in Go
Kentaro Kawano
July 26, 2019
Tweet
Share
More Decks by Kentaro Kawano
See All by Kentaro Kawano
Starting Python
kawaken
0
87
Goの時刻に関するテスト/Testing time in Go
kawaken
0
95
AWS Lambda + Go
kawaken
0
91
goaのdesignをラクに書く/Write goa design easily
kawaken
0
90
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
95
Pyvmomiとansibleのdynamic inventory
kawaken
0
98
Other Decks in Programming
See All in Programming
Introducing RemoteCompose: break your UI out of the app sandbox.
camaelon
2
270
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
18
9.3k
ドメイン駆動設計のエッセンス
masuda220
PRO
15
7k
マイベストのシンプルなデータ基盤の話 - Googleスイートとのつき合い方 / mybest-simple-data-architecture-google-nized
snhryt
0
110
Leading Effective Engineering Teams in the AI Era
addyosmani
7
680
Webサーバーサイド言語としてのRustについて
kouyuume
1
5k
オープンソースソフトウェアへの解像度🔬
utam0k
18
3.2k
Dive into Triton Internals
appleparan
0
370
퇴근 후 1억이 거래되는 서비스 만들기 | 내가 AI를 사용하는 방법
maryang
2
160
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
360
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
210
AIのバカさ加減に怒る前にやっておくこと
blueeventhorizon
0
130
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.7k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
Optimizing for Happiness
mojombo
379
70k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
Raft: Consensus for Rubyists
vanstee
140
7.2k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Building Adaptive Systems
keathley
44
2.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
658
61k
Transcript
Goでのレシーバとnilの関係 2019-07-26 Umeda.go 2019 Summer Kentaro Kawano
レシーバとは • メソッド呼び出しの対象 • 値レシーバ • ポインタレシーバ
None
レシーバがnilのメソッド呼び出しはpanicになる?
None
必ずpanicになるとは限らない レシーバがnilのメソッド呼び出しはpanicになる?
メソッド式 • RecieverType.MethodName での呼び出しが可能 • user.SayHi() は (*User).SayHi(user) と同じ •
レシーバはメソッド式の第⼀引数になる
None
どんな時にpanicする?
間接参照するとき • ポインタ型の変数(値はnil)に対して • フィールドを参照するとき • 値レシーバが必要なメソッドを呼び出すとき • 変数はレシーバの型に応じて⾃動的に型が変換される
None
None
ダメな実装例
None
⼤事なところではnilチェックをちゃんとしよう
まとめ • レシーバには値レシーバとポインタレシーバがある • レシーバはメソッド式の第⼀引数 • レシーバがnilでもpanicしないケースがある • ポインタレシーバを利⽤する場合にはnilチェックする •
すべてのメソッドでチェックする必要はない(経験則