今日から書けるリーダブルコード
by
Daiki Nojiri
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Ϧʔμϒϧίʔυ ΑΓྑ͍ίʔυΛॻͨ͘Ίͷ࣮ફతͳςΫχοΫ
Slide 2
Slide 2 text
No content
Slide 3
Slide 3 text
ࠓͷΰʔϧ ɾϦʔμϒϧίʔυͬͯͳʹʁ ɾͳΜͰϦʔμϒϧίʔυΛॻ͘ͷʁ ɾͲ͏ͬͯϦʔμϒϧίʔυΛॻ͘ͷʁ
Slide 4
Slide 4 text
Ϧʔμϒϧίʔυͬͯͳʹʁ
Slide 5
Slide 5 text
Ϧʔμϒϧίʔυ ˜ SFBEBCMFDPEF ˜ ಡΈ͍͢ίʔυ
Slide 6
Slide 6 text
ಡΈ͍͢ίʔυͬͯ ͲΜͳίʔυͩͱࢥ͍·͔͢ʁ
Slide 7
Slide 7 text
ݟ͕͍ͨͬͯΕಡΈ͍͢ʁ function isNull($array) { foreach($array as $v) { if (is_null($v)) { return false; } } return true; } Πϯσϯτ͕͖Ε͍ͳίʔυ CSSͰ͍͍͔ function isNull($array) { foreach ($array as $v) { if (is_null($v)) { return false; } } return true; }
Slide 8
Slide 8 text
Ϧʔμϒϧίʔυͱ ଞͷਓ͕࠷࣌ؒͰ ཧղͰ͖Δίʔυ
Slide 9
Slide 9 text
Ϧʔμϒϧίʔυͱ ଞͷਓ͕࠷࣌ؒͰ ཧղͰ͖Δίʔυ
Slide 10
Slide 10 text
Ϧʔμϒϧίʔυͱ ଞͷਓ͕࠷࣌ؒͰ ཧղͰ͖Δίʔυ
Slide 11
Slide 11 text
͍͚Ͳɺ͙͢ʹཧղͰ͖ͳ͍ if (split(':', $line)[0] === 'root') { // }
Slide 12
Slide 12 text
͘ͳ͍͍͔ͬͯΒӅͯ͠͠·͏ if (split(':', $line)[0] === 'root') { // } $username = split(':', $line)[0]; if ($username === 'root') { // } ˜
Slide 13
Slide 13 text
if (split(':', $line)[0] === 'root') { // } ˜ // ίϩϯͷࠨଆΛநग़͢Δ $username = split(':', $line)[0]; if ($username === root) { // } ඞཁͳΒίϝϯτ
Slide 14
Slide 14 text
ͳΜͰϦʔμϒϧίʔυΛॻ͘ͷʁ
Slide 15
Slide 15 text
ͳΜͰಡΈ͍͢ίʔυΛ ॻ͍ͨ΄͏͕͍͍ͱࢥ͍·͔͢ʁ
Slide 16
Slide 16 text
Ϧʔμϒϧίʔυͱ ଞͷਓ͕࠷࣌ؒͰ ཧղͰ͖Δίʔυ
Slide 17
Slide 17 text
։ൃ͕εϜʔζʹਐΉ ಡΈ͍͢ίʔυͳΒʜ ɾղऍʹ໎Θͳ͍ɺޡղ͕ੜ·Εͳ͍ ɾಈ࡞ͷཧղ͕ૣ͘ͳΔ ɾҾ͖ܧָ͕͗ ɾಥવϓϩδΣΫτʹΞαΠϯ͞Εͯେৎ ಡΈʹ͍͘ίʔυͩͱʜ ɾೝ͕͍͕ࣝͪ͘͏ɺޡղ͕ੜ͡Δ ɾಡΈͨ͘ͳ͘ͳΔ ɾετϨεΛײ͡Δ ɾͪΐͬͱͨ͠ػೳՃʹ͕͔͔࣌ؒΔ
Slide 18
Slide 18 text
։ൃ͕εϜʔζʹਐΉ ಡΈ͍͢ίʔυͳΒʜ ɾղऍʹ໎Θͳ͍ɺޡղ͕ੜ·Εͳ͍ ɾಈ࡞ͷཧղ͕ૣ͘ͳΔ ɾҾ͖ܧָ͕͗ ɾಥવϓϩδΣΫτʹΞαΠϯ͞Εͯେৎ ಡΈʹ͍͘ίʔυͩͱʜ ɾೝ͕͍͕ࣝͪ͘͏ɺޡղ͕ੜ͡Δ ɾಡΈͨ͘ͳ͘ͳΔ ɾετϨεΛײ͡Δ ɾͪΐͬͱͨ͠ػೳՃʹ͕͔͔࣌ؒΔ ಡΈ͍͢ίʔυΛॻ͜͏ʂ
Slide 19
Slide 19 text
Ϧʔμϒϧίʔυͬͯ Ͳ͏ͬͯॻ͘ͷʁ
Slide 20
Slide 20 text
͜͜·Ͱͷ෮श ಡΈ͍͢ίʔυͬͯͳʹʁ ˠଞͷਓ͕࠷࣌ؒͰཧղͰ͖Δίʔυ ͳΜͰಡΈ͍͢ίʔυΛॻ͘ͷʁ ˠ։ൃ͕εϜʔζʹͳΔ͔Β ɹ։ൃָ͕ʹͳΔ͔Β
Slide 21
Slide 21 text
Ͱɺ۩ମతʹͲ͏ͬͯॻ͘ͷʁ
Slide 22
Slide 22 text
ૣ͘SFUVSO͢Δ ⁞ม໊ΛΧϥϑϧʹ͢Δ JGจΛׂ͢Δ ͙͢ʹਅࣅͰ͖ΔͭͷςΫχοΫ
Slide 23
Slide 23 text
⁞໊લΛΧϥϑϧʹ͢Δ
Slide 24
Slide 24 text
⁞໊લΛΧϥϑϧʹ͢Δ CFGPSF ͳΜͰಉ͡ಈࢺʹ͕ͪ͠ ɾHFU'JMF ɾHFU+TPO ɾHFU)UNM ɾHFU%BUB ɾHFU1BHF ɾHFU6TFS/BNF ɾHFU1BSBNT ɾHFU4FBSDI2VFSZ
Slide 25
Slide 25 text
͍ΖΜͳ୯ޠ͕͋Γ·͢ HFU ͍ۙͱ͜Ζ͔Βऔͬͯ͘Δ GFUDI ԕ͍ͱ͜Ζ͔Βऔͬͯ͘Δ NBLF ൺֱతখ͞ͳͷΛ࡞Δ ࡐྉΛՃ͢Δ CVJME ൺֱతେ͖ͳͷΛ࡞Δ ΈཱͯΔ HFOFSBUF Կ͔Λมͯ͠࡞Γग़͢ DSFBUF Կͳ͍ͱ͜Ζʹ৽͘͠࡞Δ
Slide 26
Slide 26 text
⁞໊લΛΧϥϑϧʹ͢Δ BGUFS HFU)UNM QPTU ɹ%#ʹอଘ͞Ε͍ͯΔ)5.-Λऔͬͯ͘Δ GFUDI)UNM VSM ɹࢦఆͨ͠63-͔Β)5.-Λऔͬͯ͘Δ HFOFSBUF)UNM UFNQMBUF ɹςϯϓϨʔτ͔Β)5.-Λੜ͢Δ CVJME)UNM QBSUT ɹ෦ΛΈ߹Θͤͯ)5.-Λੜ͢Δ
Slide 27
Slide 27 text
ૣ͘SFUVSO͢Δ
Slide 28
Slide 28 text
ૣ͘SFUVSO͢Δ CFGPSF if (auth(‘admin’)->check() || (auth()->check() && auth()->user()->isPurchased($item) ) ) { if ($item->raw()—>exists()) { return Storage::download($item->raw); } } return redirect()->back(); ݖݶνΣοΫ ϑΝΠϧͷଘࡏ֬ೝ
Slide 29
Slide 29 text
ૣ͘SFUVSO͢Δ CFGPSF if (auth(‘admin’)->check() || (auth()->check() && auth()->user()->isPurchased($item) ) ) { if ($item->raw()—>exists()) { return Storage::download($item->raw); } } return redirect()->back(); JGจ͕ωετ͍ͯ͠Δ
Slide 30
Slide 30 text
ૣ͘SFUVSO͢Δ BGUFS if ($item->raw()—>doesNotExists()) { return redirect()->back(); } if (auth(‘admin’)->check() || (auth()->check() && auth()->user()->isPurchased($item) ) ) { return Storage::download($item->raw); } return redirect()->back();
Slide 31
Slide 31 text
ૣ͘SFUVSO͢Δ BGUFS if ($item->raw()—>doesNotExists()) { return redirect()->back(); } if (auth(‘admin’)->check() || (auth()->check() && auth()->user()->isPurchased($item) ) ) { return Storage::download($item->raw); } return redirect()->back(); ϑΝΠϧͷଘࡏ֬ೝ ݖݶνΣοΫ ϑΝΠϧ͕ͳ͍࣌ͰSFUVSO͢Εɼ ݖݶνΣοΫͰϑΝΠϧͷ͜ͱΛؾʹ͠ͳ͍͍ͯ͘
Slide 32
Slide 32 text
JGจΛׂ͢Δ
Slide 33
Slide 33 text
JGจΛׂ͢Δ BGUFS if ($item->raw()—>doesNotExists()) { return redirect()->back(); } if (auth(‘admin’)->check() || (auth()->check() && auth()->user()->isPurchased($item)) ) { return Storage::download($item->raw); } return redirect()->back(); BENJOͱVTFSΛҰʹνΣοΫ͠Α͏ͱ ͢Δ͔Βͪ͝Όͪ͝Όͯ͠͠·͏
Slide 34
Slide 34 text
JGจΛׂ͢Δ BGUFS if ($item->raw()—>doesNotExists()) { return redirect()->back(); } if (auth(‘admin’)->check()) { return Storage::download($item->raw); } if (auth()->check() && auth()->user()->isPurchased($item)) { return Storage::download($item->raw); } return redirect()->back(); BENJOͷݖݶνΣοΫ VTFSͷݖݶνΣοΫ
Slide 35
Slide 35 text
JGจΛׂ͢Δ BGUFS if ($item->raw()—>doesNotExists()) { return redirect()->back(); } if (auth(‘admin’)->check()) { return Storage::download($item->raw); } if (auth()->check() && auth()->user()->isPurchased($item)) { return Storage::download($item->raw); } return redirect()->back(); ϑΝΠϧͷଘࡏ֬ೝ BENJOͷݖݶνΣοΫ VTFSͷݖݶνΣοΫ
Slide 36
Slide 36 text
ࠓͷ·ͱΊ ಡΈ͍͢ίʔυͬͯͳʹʁ ˠଞͷਓ͕࠷࣌ؒͰཧղͰ͖Δίʔυ ͳΜͰಡΈ͍͢ίʔυΛॻ͘ͷʁ ˠ։ൃ͕εϜʔζʹͳΔ͔Β Ͳ͏ͬͯಡΈ͍͢ίʔυΛॻ͘ͷʁ ˠ͍ΖΜͳςΫχοΫ͕͋ͬͯɺ ɹʰϦʔμϒϧίʔυʱͰͨ͘͞Μհ͞Εͯ ɹ͍Δ
Slide 37
Slide 37 text
͓·͚ ϘπҊ ͔ͤͬ͘ͳͷͰ͚ͱ͖·͢
Slide 38
Slide 38 text
⁞໊લΛΧϥϑϧʹ͢Δ CFGPSF %#ͷΧϥϜ໊Λྫʹ ཧ໊ ཧ໊ OFXTEFUBJM ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ TFSJFTEFTDSJQUJPO ֓ཁ DMJFOUTEFTDSJQUJPO උߟ
Slide 39
Slide 39 text
%#ͷΧϥϜ໊Λྫʹ ཧ໊ ཧ໊ OFXTEFUBJM ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ TFSJFTEFTDSJQUJPO ֓ཁ DMJFOUTEFTDSJQUJPO උߟ EFUBJMৄࡉɺEFTDSJQUJPOઆ໌ ⁞໊લΛΧϥϑϧʹ͢Δ CFGPSF
Slide 40
Slide 40 text
%#ͷΧϥϜ໊Λྫʹ ཧ໊ ཧ໊ OFXTEFUBJM ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ TFSJFTEFTDSJQUJPO ֓ཁ DMJFOUTEFTDSJQUJPO උߟ ཧ໊͕ҧ͏ͷʹཧ໊ಉ͡ ⁞໊લΛΧϥϑϧʹ͢Δ CFGPSF
Slide 41
Slide 41 text
%#ͷΧϥϜ໊Λྫʹ ཧ໊ ཧ໊ OFXTEFUBJM ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ TFSJFTEFTDSJQUJPO ֓ཁ DMJFOUTEFTDSJQUJPO උߟ ཧ໊͕ҧ͏ͷʹཧ໊ಉ͡ ⁞໊લΛΧϥϑϧʹ͢Δ CFGPSF
Slide 42
Slide 42 text
%#ͷΧϥϜ໊Λྫʹ ཧ໊ ཧ໊ OFXTEFUBJM ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ TFSJFTEFTDSJQUJPO ֓ཁ DMJFOUTEFTDSJQUJPO උߟ ύοͱݟ͚ͨͩͰΘ͔Βͳ͍ ⁞໊લΛΧϥϑϧʹ͢Δ CFGPSF
Slide 43
Slide 43 text
⁞໊લΛΧϥϑϧʹ͢Δ BGUFS ӳ୯ޠͷόϦΤʔγϣϯΛ૿ͯ͠ΈΔ ཧ໊ ཧ໊ OFXTCPEZ ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ ৄࡉ BVUIPSTEFTDSJQUJPO ஶऀʹ͍ͭͯ આ໌ TFSJFTPWFSWJFX ֓ཁ DMJFOUTSFNBSL උߟ
Slide 44
Slide 44 text
ӳ୯ޠͷόϦΤʔγϣϯΛ૿ͯ͠ΈΔ ཧ໊ ཧ໊ OFXTCPEZ ͓Βͤ༰ BVUIPSTEFUBJM ஶऀʹ͍ͭͯ ৄࡉ BVUIPSTEFTDSJQUJPO ஶऀʹ͍ͭͯ આ໌ TFSJFTPWFSWJFX ֓ཁ DMJFOUTSFNBSL උߟ ӳ୯ޠΛ͓ͬͯ͘ ඞཁ͕͋Δ͚Ͳɺ ཧ໊Λݟ͚ͨͩͰ Λ૾Ͱ͖Δ ⁞໊લΛΧϥϑϧʹ͢Δ BGUFS