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言語】名前付き戻り値
Search
Tomoki Ota
August 02, 2024
Programming
0
13
【Go言語】名前付き戻り値
Go言語の名前付き戻り値の違いについて、解説しています。
【Qiita】
https://qiita.com/twrcd1227/items/2b6506ad57d3dc0b12d1
Tomoki Ota
August 02, 2024
Tweet
Share
More Decks by Tomoki Ota
See All by Tomoki Ota
【Go言語】イテレータ
tomo1227
0
5
【Go言語】エラーハンドリング
tomo1227
0
8
AIに淘汰されないようにするには?
tomo1227
0
12
range.pdf
tomo1227
0
5
【Go言語】break
tomo1227
0
5
【Go言語】反復処理
tomo1227
0
4
【Go言語】map
tomo1227
0
16
【Go言語】値の比較
tomo1227
0
17
【Go言語】値レシーバ v.s. ポインタレシーバ
tomo1227
0
16
Other Decks in Programming
See All in Programming
大公開!iOS開発の悩みトップ5 〜iOSDC Japan 2024〜
ryunakayama
0
190
Scala アプリケーションのビルドを改善してデプロイ時間を 1/4 にした話 | How I improved the build of my Scala application and reduced deployment time by 4x
nomadblacky
1
160
React + TextAliveでカッコいいLyric Applicatioinを作ろう!!
tosuri13
0
400
unique パッケージから学ぶ interning と weak reference @ Asakusa.go#3
karamaru
2
740
LangChainの現在とv0.3にむけて
os1ma
4
840
Some more adventure of Happy Eyeballs
coe401_
2
180
Go1.23で入った errorsパッケージの小さなアプデ
kuro_kurorrr
2
330
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
260
労務ドメインを快適に開発する方法 / How to Comfortably Develop in the Labor Domain
yuki21
1
250
実践!難読化ガイド
mitchan
0
120
エラーレスポンス設計から考える、0→1開発におけるGraphQLへの向き合い方
bicstone
5
1.5k
GraphQLの魅力を引き出すAndroidクライアント実装
morux2
3
320
Featured
See All Featured
Statistics for Hackers
jakevdp
793
220k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.2k
Writing Fast Ruby
sferik
623
60k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
89
16k
What's new in Ruby 2.0
geeforr
340
31k
Speed Design
sergeychernyshev
22
420
Java REST API Framework Comparison - PWX 2021
mraible
PRO
27
7.4k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Building Adaptive Systems
keathley
36
2.1k
Unsuck your backbone
ammeep
667
57k
Building Flexible Design Systems
yeseniaperezcruz
325
37k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
Transcript
Tomoki Ota ʲGoݴޠʳ໊લ͖Γ
໊લ͖Γͱʁ ໊લ͖Γͷ༻ྫ ແҙຯͳ໊લ͖Γ ՄಡੑҎ֎ͷ໊લ͖Γ ۭreturn ໊લ͖Γͷ෭࡞༻ ·ͱΊ ΞδΣϯμ
໊લ͖Γͱʁ
GoͰ໊લ͖Γ(Named Return Value) ͋·ΓΘΕͳ͍ ໊લ͖Γͱʁ
໊લ͖ΓΛ͏ͱɺҾͳ͠ͷۭreturnจΛݺͼग़ͤΔ ໊લ͖Γͱʁ
໊લ͖Γͷ༻ྫ
໊લ͖Γͷ༻ྫ
໊લ͖Γͷ༻ྫ
ແҙຯͳ໊લ͖Γ
ແҙຯͳ໊લ͖Γ errorܕ͕errorͰ͋Δ͜ͱࣗ໌
ՄಡੑҎ֎ͷ໊લ͖Γ
ՄಡੑҎ֎ͷ໊લ͖Γ
ՄಡੑҎ֎ͷ໊લ͖Γ
ۭreturn
ۭreturn ۭreturnҰൠతʹ͍ؔͰ༻͍ΒΕΔɻ ͍ؔͰ༻͢ΔͱɺՄಡੑ͕ѱ͘ͳΔͷͰɺ༻ ͖͢Ͱͳ͍ɻ
ۭreturn 1ͭͷؔͰɺۭreturnΛ͏͔ɺҾͷ͋Δ returnΛ༻͢Δ͔Ұ؏ੑΛอͭ͜ͱ͕େࣄɻ
໊લ͖Γͷ෭࡞༻
໊લ͖Γͷ෭࡞༻ ໊લ͖ΓɺθϩͰॳظԽ͞ΕΔͷͰɺҙਤ ͠ͳ͍όάΛট͘Մೳੑ͕͋Δ
໊લ͖Γͷ෭࡞༻ ઌ΄ͲͷgetCoordinatesΛ֦ ு͠ɺॅॴΛݕূͯ͠ɺ࠲ඪΛ औಘ͢Δɻ·ͨɺ్தͰɺί ϯςΩετͰɺσουϥΠϯ͕ ա͗ͯͳ͍͔Ωϟϯηϧ͞ Ε͍ͯͳ͍͔Λݕࠪ͢Δɻ
໊લ͖Γͷ෭࡞༻ if ctx.Err() != nilͰฦ͞ΕΤ ϥʔerr͕ͩɺerrʹԿ ೖ͓ͯ͠ΒͣɺθϩͰ͋Δ nil͔͠ฦ͞ͳ͍ɻ
໊લ͖Γͷ෭࡞༻ err໊લ͖ΓʹΑͬͯ ॳظԽ͍ͯ͠ΔͷͰɺ໊લ͖ Γ͕ͳ͚ΕɺίϯύΠϧ ΤϥʔͱͳΔɻ
ղܾ๏1
ղܾ๏2