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
読みやすいコードを書こう
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yutorin
May 16, 2022
Programming
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
読みやすいコードを書こう
社内のLT会で発表したスライドです。
Yutorin
May 16, 2022
Transcript
15 slides
読みやすいコードを書こう 2022/05/13 - Yutorin
2 自己紹介 Yutorin 日本語が下手です
・読みにくいコードがあると、 読みたくないし時間もかかる! 3 読みやすいコード書いてる? reference: https://qiita.com/shimataro999/items/ef6cd838d56f1fe87015
・レビューしたくなくなる ・治安が悪くなる ・ = 読みにくいコードが再生産される ・なにより次の日自分で読めない! 4 自分が読めればええやん?
いくつか抜粋して紹介します ・何が良いコードなのか? ・良くなるコードの書き方 ・コメントについて 5 そのために古事記を読め
・良いコードは1行で凄いことをすることじゃなくて、 理解しやすいかどうか ・コードは他の人が最短時間で理解出来るようにする ・そのためにコメントをつけることも大事 ・常に「このコードは理解しやすいだろうか?」と頭の中の誰かに問い 続ける 6 理解しやすいコード
・dataとかsizeとか曖昧な単語ではなく、明確で正確な単語を使おう ・data: property, description, result ・size: height, bytes, weight ・類語辞典を使おう
・get 類義語 ・get synonyms とか検索すると色々でてくる 7 名前に情報を詰め込もう
・変数に入っている情報が名前だけで読み取れないなら、追加したほう がいい ・base64化したchime_idなら encodedChimeId とか、 base64ChimeIdとか。 ・圧縮したjpg画像なら compressedImage とか compressedJpgとか
8 名前に情報を追加する
・プログラミングの時間のほとんどはコードを読む時間 ・同じようなことをするなら、同じようなものを作ろう 9 一貫性のあるコードを書こう
・コメントの目的は、書き手の意図を読み手に知らせること ・コードを書いているときの自分の考えを記録する ・他の方法がある場合、なんでこの方法を選んだか ・欠陥がある場合はFIXME、やることが残っているならTODOなど ・関数名やコード軽く眺めるだけでは得られない必要な情報 ・e.g. 7日より前のファイルは消えているためその日付以前は filter()している とか。 10 コメントをすべきこと
・コードからすぐわかることをコメントに書かない ・コメントをつけるよりも変数名を変える方がいい場合もある 11 コメントすべきではないこと
・コメント書いたほうが良いかな?と思った場合はとりあえず書こう ・後から丁寧に書き直してみたり、今まで振り返ってきたこと(改善 点を見つけてより良くする)をやってみる。 ・// ヤバいかも。重複してたら壊れちゃう。 →// 注意:この関数は重複を処理できません(難しいので) 12 とりあえず書いてみよう
・読む人の気持ちになろう ・コードを通して他の人と対話するように ・英語脳になろう ・英語が伝わってるかどうか考えることで良いコードになる・・かも? ・こだわりを持とう 13 要は...
14 読んでみてね!おわり!
15
More Decks by Yutorin
See All by Yutorin
新卒でサービス立ち上げから Hasuraを使って3年経った振り返り
yutorin
0
780
Other Decks in Programming
See All in Programming
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
420
Stage 3でも仕様は変わる。アプリケーション開発者のためのTC39プロセスの読み方
bicstone
1
850
How SRE Grew Out of Server-Side Work and Became the Team's Own / サーバサイドから始まったSREを チームに渡すまで
maaaato
1
340
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
450
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
210
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
520
Jujutsu で毎日のバージョン管理に「安心」と「直感性」を
oukayuka
0
110
Datadog を OTel にするメリットを考察する — Datadog との併用を実アプリで確かめる / Examining the Benefits of Moving Datadog to OTel — Testing OTel Alongside Datadog in a Real App
seike460
PRO
1
100
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
440
眠らない開発チームの作り方
biwakonbu
0
160
Getting Started with Vibe Coding
miccheng
0
250
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
First, design no harm
axbom
PRO
2
1.4k
Design in an AI World
tapps
1
400
Building Applications with DynamoDB
mza
96
7.3k
The agentic SEO stack - context over prompts
schlessera
0
1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
650
Making Projects Easy
brettharned
120
6.9k