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
44
【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
88
アーキテクチャとビジネスロジック
tomo1227
0
86
【Go言語】テスト
tomo1227
0
50
【Go言語】クロージャ
tomo1227
0
250
【Go言語】イテレータ
tomo1227
0
67
【Go言語】エラーハンドリング
tomo1227
0
56
AIに淘汰されないようにするには?
tomo1227
0
57
【Go言語】range
tomo1227
0
60
【Go言語】break
tomo1227
0
59
Other Decks in Programming
See All in Programming
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
440
フロントエンドのmonorepo化と責務分離のリアーキテクト
kajitack
2
160
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
0
250
Kiroの仕様駆動開発から見えてきたAIコーディングとの正しい付き合い方
clshinji
1
190
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
360
TanStack DB ~状態管理の新しい考え方~
bmthd
2
430
AIコーディングAgentとの向き合い方
eycjur
0
250
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
140
rage against annotate_predecessor
junk0612
0
160
Laravel Boost 超入門
fire_arlo
2
180
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
1.4k
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
160
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Building Applications with DynamoDB
mza
96
6.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
For a Future-Friendly Web
brad_frost
179
9.9k
We Have a Design System, Now What?
morganepeng
53
7.8k
Gamification - CAS2011
davidbonilla
81
5.4k
Site-Speed That Sticks
csswizardry
10
810
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
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