Upgrade to Pro — share decks privately, control downloads, hide ads and more …

クソコードの測り方

 クソコードの測り方

PHPBLT#3 で話した内容です。

Hiraku NAKANO

March 01, 2016
Tweet

More Decks by Hiraku NAKANO

Other Decks in Technology

Transcript

  1. Ϋιίʔυͷ

    ଌΓํ
    PHPBLT #3
    @Hiraku

    View full-size slide

  2. ࣗݾ঺հ
    • த໺ ୓ (@Hiraku)
    • ޱบʮcomposer͕஗͍ʯʮޫ͕஗͍ʯˡNew!
    • ޫ஗͍໰୊Λࠀ෰ͯ͠composerΛ10ഒ଎ͨ͘͠࿩

    http://tech.mercari.com/entry/2016/02/01/164829

    View full-size slide

  3. hirak/prestissimo 

    (composerߴ଎ԽϓϥάΠϯ)
    Πϯετʔϧ͢Δ͚ͩͰ10ഒ͙Β͍଎͘ͳΓ·͢

    View full-size slide

  4. hirak/prestissimo
    • ͝੠ԉ͋Γ͕ͱ͏͍͟͝·͢

    View full-size slide

  5. prestissimoΛൃද͔ͯ͠Β

    Ұϲ݄

    View full-size slide

  6. ͜͜Ұϲ݄ͷ੒Ռ

    1/24 2/28

    View full-size slide

  7. Scrutinizer
    • ίʔυ඼࣭ʹ఺਺Λ͚ͭΔαʔϏε (OSSͳΒແྉʂ)
    • όάͬΆ͍ॴΛݟ͚ͭͯ͘ΕΔ
    • 10఺ຬ఺

    View full-size slide

  8. ϝιουผͷ఺਺

    View full-size slide

  9. ScrutinizerείΞͷ্͛ํ
    • ྘৭(AϥϯΫ)ͷϝιου͹͔ΓʹͳͬͨΒɺ
    10.00ʹͳΔ
    • ଌఆ݁Ռ͸৭ʑग़ͯ͘Δ͕ɺͲ͜Λमਖ਼͢Ε
    ͹͍͍ͷ͔ʁ

    View full-size slide

  10. ͜͜ʹ஫໨

    View full-size slide

  11. C.R.A.P.
    =Change Risk Anti-Patterns

    View full-size slide

  12. ௚༁͢Δͱ

    Ϋι౓

    View full-size slide

  13. CRAPͱ͸
    • Ϋιίʔυͷ౓߹͍Λఆྔతʹදͨ͠਺ࣈ
    • 1ʙແݶେ
    • If CRAP1(m) > 30, we consider the method
    to be CRAPpy.

    View full-size slide

  14. Googleͷϒϩά͕ৄ͍͠
    http://googletesting.blogspot.jp/2011/02/this-code-is-crap.html

    View full-size slide

  15. comp(m) = ॥؀తෳࡶ౓
    cov(m) = ςετΧόϨοδ

    View full-size slide

  16. comp(m)=॥؀తෳࡶ౓
    • ίʔυͷ෼ذΛ਺͑ͨ΋ͷ
    • if΍forΛ࢖͏ͱ1ͣͭ૿͑Δ(্ݶ͸ͳ͍)
    • ෼ذ͕ͳ͚Ε͹1

    View full-size slide

  17. cov(m)=ςετΧόϨοδ
    • ϢχοτςετͰ࣮ߦ͞Εͨίʔυͷׂ߹
    • ͜͜Ͱݴ͏ΧόϨοδ͸C0ΧόϨοδͷ͜ͱ

    Ұ౓Ͱ΋શߦ࣮ߦ͍ͯ͠Ε͹100%
    • 0%ʙ100%ͷؒͷ਺ࣈ

    View full-size slide

  18. cov(m)͕100%ͩͬͨΒ
    ͕͜͜0ʹͳΔΑͶ

    View full-size slide

  19. comp(m)=1, cov(m)=0%
    ͕͜͜1ʹͳΔΑͶ
    ͜͜΋1ʹͳΔΑͶ

    View full-size slide

  20. CRAPͱม਺ͷؔ܎
    • comp(m) ্͕͕Δͱ
    2৐ͷ੎͍Ͱ૿͑Δ
    • cov(m)্͕͕Δͱগ
    ͠؇࿨͞ΕΔ
    • ΧόϨοδ͕100%Ͱ
    ΋ɺෳࡶ౓͕30Λ௒
    ͍͑ͯͨΒμϝ

    View full-size slide

  21. ྘৭͕CRAP<30

    View full-size slide

  22. CRAPείΞͷԼ͛ํ

    View full-size slide

  23. جຊతͳϧʔϧ
    • ෳࡶ౓͸ϝιουผͳͷͰɺࡉ͔͘෼ׂ͢Δ
    ͱݮΔ
    • ϢχοτςετΛॻ͚͹ݮΔ

    View full-size slide

  24. ݱ࣮తͳ࿩
    • ෳࡶͳίʔυ͸Ϣχοτςετͮ͠Β͍
    • ςετ͠΍͘͢ॻ͖׵͑ͯΏ͘
    • →ࣗવͱίʔυ͕෼ׂ͞ΕΔʂ

    View full-size slide

  25. ιʔεΛ୹͘͢Δ
    • ಉ͡ϩδοΫΛ୹͍ίʔυͰ࠶ݱ͢Δ
    • ϥΠϒϥϦؔ਺ͷ׆༻
    • ίϐϖΛݮΒͯؔ͠਺ڞ௨Խ
    • ࠶ؼʹॻ͖׵͑Δ

    View full-size slide

  26. PHPUnitͰ΋CRAPܭଌ
    • ΧόϨοδϨϙʔτͰCRAPείΞಡΊ·͢

    View full-size slide

  27. prestissimoͷي੻

    View full-size slide

  28. ࠓ೔ͷ·ͱΊ
    • ΫιίʔυΛఆྔతʹ൑ఆ͢Δํ๏͕͋Δ
    • ଌͬͯΈΔͱ໘ന͍ΑɺPHPUnitͰ΋Θ͔ΔΑ
    • Ғͦ͏ʹղઆ͚ͨ͠ͲScrutinizerείΞ10.00
    ·ͩ౸ୡͯ͠ͳ͍

    View full-size slide

  29. ิ଍ɿ

    CRAP͕ڭ͑ͯ͘Εͳ͍΋ͷ
    • ιϑτ΢ΣΞ͕଎͍͔Ͳ͏͔
    • ໾ʹཱ͔ͭʢΧωΛੜΉ͔ʣ
    • ֦ுੑʹ༏Ε͍ͯΔ͔
    (͋͘·Ͱෳࡶ౓ͷ࿩Ͱ͋Δ͜ͱʹ஫ҙ)

    View full-size slide