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
38
【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
アーキテクチャの価値
tomo1227
0
53
アーキテクチャとビジネスロジック
tomo1227
0
58
【Go言語】テスト
tomo1227
0
32
【Go言語】クロージャ
tomo1227
0
220
【Go言語】イテレータ
tomo1227
0
39
【Go言語】エラーハンドリング
tomo1227
0
41
AIに淘汰されないようにするには?
tomo1227
0
37
【Go言語】range
tomo1227
0
31
【Go言語】break
tomo1227
0
39
Other Decks in Programming
See All in Programming
Jakarta EE Meets AI
ivargrimstad
0
770
開発者フレンドリーで顧客も満足?Platformの秘密
algoartis
0
150
AIコーディングの理想と現実
tomohisa
35
37k
RuboCop: Modularity and AST Insights
koic
2
2.4k
Vibe Coding の話をしよう
schroneko
13
3.6k
監視 やばい
syossan27
12
10k
Instrumentsを使用した アプリのパフォーマンス向上方法
hinakko
0
230
大LLM時代にこの先生きのこるには-ITエンジニア編
fumiyakume
7
3.3k
Road to RubyKaigi: Making Tinny Chiptunes with Ruby
makicamel
4
540
Browser and UI #2 HTML/ARIA
ken7253
2
170
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
750
Improve my own Ruby
sisshiki1969
0
100
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
The Cult of Friendly URLs
andyhume
78
6.3k
Making the Leap to Tech Lead
cromwellryan
133
9.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Navigating Team Friction
lara
185
15k
Statistics for Hackers
jakevdp
798
220k
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.5k
The Language of Interfaces
destraynor
157
25k
Typedesign – Prime Four
hannesfritz
41
2.6k
Fireside Chat
paigeccino
37
3.4k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
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