Refactoring: What, Why and When

Refactoring: What, Why and When

リファクタリングとはなんなのか、どうして必要なのか、そしていつ実行するべきなのか。
本セッションではそんなリファクタリングの基礎について紹介していきます。

32f242f75b63e7174b493446de54a6b8?s=128

Yuya Saito

June 21, 2014
Tweet

Transcript

  1. What, Why and When Refactoring Refactoring Yuya Saito @ Remixing

  2. Remixing Welcome to

  3. Yuya Saito @ Rich Media

  4. Refactoring Refactoring ? ? ?

  5. Agenda Agenda ϦϑΝΫλϦϯάͱ͸ͲΜͳ΋ͷͳͷ͔ ͳͥϦϑΝΫλϦϯάΛ͢Δඞཁ͕͋Δͷ͔ ͍ͭ΍Δ΋ͷͳͷ͔ What Why When

  6. Refactoring: Improving the Design of Existing Code by Martin Fowler

  7. What What ϦϑΝΫλϦϯάͱ͸

  8. “The first draft of anything is shit.” — Ernest Hemingway

  9. Refactoring (noun): a change made to the internal structure of

    software to make it easier to understand and cheaper to modify without changing its observable behaviour.
  10. ϦϑΝΫλϦϯά ໊ࢺ  ؍ଌͰ͖ΔৼΔ෣͍Λมߋ͢Δ͜ͱͳ͘ɺ ΑΓཧղ͠΍͘͢ɺมߋ͠΍͘͢ͳΔΑ͏ɺ ιϑτ΢ΣΞͷ಺෦తͳߏ଄Λมߋ͢Δ͜ͱɻ

  11. ιʔείʔυΛΩϨΠʹ͢Δ͜ͱ tl;dr

  12. ཧղ͠΍͘͢ɺ Point 1/2 มߋ͠΍͘͢͢Δɻ ιϑτ΢ΣΞΛ

  13. ؍ଌՄೳͳৼΔ෣͍Λมߋ͠ͳ͍ Point 2/2

  14. Why Why ͳͥඞཁͳͷ͔

  15. 100% 100%

  16. 42 42

  17. Improves the Design of Software Refactoring Refactoring ιϑτ΢ΣΞͷσβΠϯΛ޲্ͤ͞Δ

  18. None
  19. σβΠϯ͸࣌ؒͷܦաʹΑͬͯ ඼࣭͕Լ͕͍ͬͯ͘΋ͷ

  20. ϓϩάϥϛϯάͷੈքͰ΋ ·ͬͨ͘ಉ͜͡ͱ͕ݴ͑Δ

  21. มԽͷڱؒʹஔ͖๨Εͯ͠·ͬͨɺ ົͳʹ͓͍͕͢ΔίʔυΛݩʑͷσβΠϯʹ ߹Θͤͯॻ͖׵͑ΔͨΊʹଘࡏ͢Δɻ Refactoring Refactoring

  22. Makes Software Easier to Understand Refactoring Refactoring ιϑτ΢ΣΞΛཧղ͢Δ͜ͱΛखॿ͚ͯ͘͠ΕΔ

  23. Lazy Lazy

  24. ॻ͍ͨίʔυʹ͓֮͑ͯ͘΂͖͜ͱ ͢΂ͯΛୗ͢ɻ ࢒ͨ͠͸ͣͷʮ͓֮͑ͯ͘΂͖ʯ͜ͱΛ ಡΈऔΕͳ͍ɻ u

  25. ଞਓ͕ॻ͍ͨίʔυ΋ɺ ࣗ෼͕ॻ͍ͨίʔυ΋ཧղͰ͖ΔΑ͏ ॻ͖׵͑Δɻ Refactoring Refactoring

  26. When When ͍ͭϦϑΝΫλϦϯάΛ͢Δ΂͖͔

  27. ࣗ෼ͷ͍ͨ৔ॴ͸ɺͦ͜Λग़ͯߦ͘ͱ͖ɺ དྷͨ࣌ΑΓ΋͖Ε͍ʹ͠ͳ͚Ε͹ͳΒͳ͍ɻ — The Boy Scout Rule

  28. ͲͷϓϩδΣΫτͰ΋ϦϑΝΫλϦϯά͕ ඞཁͰ͋Δͱ͍͏ೝ͕ࣝ͋Δɻ

  29. Ͳ͏΍ͬͯϦϑΝΫλϦϯάͷ ࣌ؒΛ֬อ͢Δ͔ Problem is: Problem is:

  30. Answer is Simple Answer is Simple ͦΜͳ࣌ؒ͸͍ͭ·Ͱͨͬͯ΋ ֬อͰ͖ͳ͍ɻ

  31. ن໛ͷେখ͸͋ΕͲιʔείʔυʹ͸ ඞͣඒ͍͠ͱ͸ݴ͑ͳ͍෦෼͕͋Δ΋ͷɻ

  32. ࣗ෼ͷ͍ͨ৔ॴ͸ɺͦ͜Λग़ͯߦ͘ͱ͖ɺ དྷͨ࣌ΑΓ΋͖Ε͍ʹ͠ͳ͚Ε͹ͳΒͳ͍ɻ — The Boy Scout Rule

  33. ϦϑΝΫλϦϯά͸ظؒΛ ܾΊͯߦ͏΋ͷͰ͸ͳ͍ɻ

  34. Rule of Three Rule of Three

  35. 1,2,_,_,_,_

  36. 1,2,3,_,_,_

  37. None
  38. “The first time you do something, you just do it.

    The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor.” — Don Roberts
  39. ·ͣ࢝Ίͷճ໨ʹԿ͔Λ͢Δ৔߹͸ɺ ͨͩͦΕΛ͢Δ͚ͩɻ ճ໨ʹԿ͔ࣅͨ͜ͱΛ͢Δ৔߹͸ɺ ॏෳʹද৘ΛಶΒͤͳ͕Β΋ɺ ͦͷॏෳ͍ͯ͠Δ͜ͱΛ͢Δɻ ճ໨ʹͦͷࣅͨԿ͔Λ͢Δࡍɺ ϦϑΝΫλΛߦ͏ɻ — Don Roberts

  40. Outro Outro ·ͱΊ

  41. ೏ͬͨΒɺม͑Δɻ — The Rule of Baby Rearing

  42. Code smells Code smells

  43. ೏͍Λ͔͗෼͚Δೳྗ͕ܦݧͱΑ͹ΕΔ΋ͷ

  44. Take away Take away

  45. 1/2

  46. 2/2 ϦϑΝΫλϦϯά͸ ظؒΛܾΊͯߦ͏΋ͷͰ͸ͳ͘ɺ ௨ৗۀ຿ͷϫʔΫϑϩʔ಺Ͱߦ͏΋ͷͰ͢ɻ

  47. The Long Goodbye by Raymond Chandler

  48. “There is no trap so deadly as the trap you

    set for yourself.” — Philip Marlowe
  49. “ࣗ෼Ͱࣗ෼ʹ࢓ֻ͚Δ᠘΄Ͳ ͨͪͷѱ͍᠘͸ͳ͍ɻ” — Philip Marlowe

  50. Thank You! Thank You! @cssradar @cssradar