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

LegacySystem.pdf

k-motoyan-diverse
November 27, 2018
2.8k

 LegacySystem.pdf

k-motoyan-diverse

November 27, 2018
Tweet

Transcript

  1. レガシーシステムが あらわれた!
    diverse.tech #1
    ~ レガシーシステムを かたらう よる ~

    View Slide

  2. これは レガシーな プログラムを
    かいぜんしていくための はじめの
    いっぽをふみだす おはなしです。

    View Slide

  3. アバウト ミー
    •かぶしきがいしゃ Diverse
    •にゅうしゃ 3かげつめの かけだし サーバーサイドエンジニア
    •Github
    •https://github.com/k-motoyan

    View Slide

  4. それは あるひの できごとでした…

    View Slide

  5. 「この むかしから ある システムに
     あたらしく きのうを ついかしたいんだ。」

    View Slide

  6. 「この むかしから ある システムに
     あたらしく きのうを ついかしたいんだ。」
    はい
      いいえ

    View Slide

  7. 「この むかしから ある システムに
     あたらしく きのうを ついかしたいんだ。」
    はい
    → いいえ

    View Slide

  8. 「げんじつ からは にげられない!」

    View Slide

  9. 「どうする?」
    コードを みる
      しようを かくにんする

    View Slide

  10. 「どうする?」
    コードを みる
    → しようを かくにんする

    View Slide

  11. 「しようを しっているひとは
     もういないよ。」

    View Slide

  12. 「かいはつチームの めのまえが
     まっくらになった。」

    View Slide

  13. View Slide

  14. 「どうする?」
    コードを みる
      しようを かくにんする

    View Slide

  15. 「どうする?」
    → コードを みる
      しようを かくにんする

    View Slide

  16. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  17. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end
    これは かくうの ソースコードです

    View Slide

  18. 「さわるだけで デグレードしそうな
     ソースコードだ。」

    View Slide

  19. 「どうする?」
    はらをくくって きのうを ついかする
      テストを かく

    View Slide

  20. 「どうする?」
    はらをくくって きのうを ついかする
    → テストを かく

    View Slide

  21. 「どの テストを かく?」
    ユニット テスト
      しようか テスト

    View Slide

  22. 「どの テストを かく?」
    → ユニット テスト
      しようか テスト

    View Slide

  23. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  24. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  25. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  26. 「いぞんどの たかい
     コードが うめこまれていて
     ユニットテストを かくことが むずかしい。」

    View Slide

  27. 「どの テストを かく?」
    ユニット テスト
      しようか テスト

    View Slide

  28. 「どの テストを かく?」
    ユニット テスト
    → しようか テスト

    View Slide

  29. ʊਓਓਓਓਓਓਓਓਓਓʊ
    ʼɹ͠Α͏͔ɹςετɹʻ
    ʉ:?:?:?:?:?:?:?:?:ʉ

    View Slide

  30. ࢓༷Խςετ
    DIBSBDUFSJ[BUJPOUFTU

    ࢓༷Խςετͱ͸ɺίʔυͷݱࡏͷৼΔ෣͍Λ֬ೝ͢ΔͨΊ
    ͷςετͰ͢ɻ
    ݱࡏͷৼΔ෣͍Λςετͱͯ͠ॻ͖ى͜͢͜ͱͰɺͦͷίʔ
    υʹରͯ͠मਖ਼ΛՃ͑ͨ࠶ʹ൐͏ΤϯόάɾσάϨʔυΛ཈
    ੍͢ΔޮՌ͕͋Γ·͢ɻ
    ͋͘·Ͱ΋ݱࡏͷৼΔ෣͍Λ֬ೝ͢ΔͨΊͷςετͰ͋Γɺ
    ࢓༷͕੔උ͞ΕΔλΠϛϯάͰ࢓༷Խςετ͸ࣺͯΔ͔मਖ਼
    ͢Δඞཁ͕ग़ͯ͘Δɻ

    View Slide

  31. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  32. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  33. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end

    View Slide

  34. class UserController < ApplicationController
    def index
    @user = User.find_by!(id: params[:id], status: :active)
    if [email protected]_debug_user?
    AccessLog.create user_id: @user.id,
    user_name: @user.name,
    access_page: "user_index"
    end
    begin
    @user.friends.each do |friend|
    if !friend.enabled_friend_access_notification
    @notification =
    Notification.create user_id: @friend.id
    friend_id: @user.id
    message: "#{@user.name}͕ϚΠϖʔδʹΞΫηε͠·ͨ͠"
    end
    PushService.send(@notification)
    end
    rescue => e
    @error = ErrorLog.create message: "ϑϨϯυͷ௨஌ʹࣦഊ͠·ͨ͠"
    redirect_to error_page_path(@error)
    end
    case @user.score
    when 0..10
    render :score1_user
    when 11..30
    render :score2_user
    when 31..50
    render :score3_user
    when 51..70
    render :score4_user
    when 81..100
    render :score5_user
    end
    end
    end
    71 から 80 のケースがない!?

    View Slide

  35. 「バグなのか しようなのか わからない
     コードに しようか テストを かいた。」

    View Slide

  36. 「こうかは バツグンだ!」

    View Slide

  37. 「かいはつチームは しようか テスト で、
     きのうついかの かいはつが
     おこなえるようになった!!」

    View Slide

  38. こうして むかしからある
    システムに きのうを ついかする
    おしごとを こなすことが できました。

    View Slide

  39. しかし むかしからある、
    レガシーシステムがもつ もんだいは
    これだけでは ありません。

    View Slide

  40. かいはつチームの たたかいは 
    まだまだ つづく…

    View Slide

  41. さんこう ぶんけん
    ΫϦεɾόʔνϟϧʢஶʣɹ٢઒ɹ๜෉ʢ຋༁ʣ
    ʰϨΨγʔιϑτ΢ΣΞվળΨΠυʱɹᠳӭࣾ

    View Slide

  42. Special Thanks
    υοτ෩ϑΥϯτ
    SDFɿIUUQTXXXIPHFSBDPNQDCGPOU
    ձ৔ઃӦΛͯ͘͠Εͨ%JWFSTFͷํʑ
    ͦͯ͠ɺࠓ೔͝དྷ৔௖͍ͨօ༷

    View Slide