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

PHPエンジニアによるScalaエンジニアへの転身とその手引き

Shingo Harada
November 11, 2018

 PHPエンジニアによるScalaエンジニアへの転身とその手引き

Shingo Harada

November 11, 2018
Tweet

Other Decks in Technology

Transcript

  1. ݪాਅޗ
    1)1ΤϯδχΞʹΑΔ4DBMBΤϯδ
    χΞ΁ͷస਎ͱͦͷखҾ͖
    4DBMBؔ੢4VNNJU

    View full-size slide

  2. 2017/11/11 © ChatWork All rights reserved. 2
    ࣗݾ঺հ
    ‣ $IBU8PSLגࣜձࣾαʔόʔαΠυ։ൃ෦
    ‣ ೖࣾ ݱࡏͰஸ౓೥͙Β͍

    ‣ 1)1ΤϯδχΞͱͯ͠ೖࣾ
    ‣ ࠷ۙ4DBMBϓϩμΫτʹ΋KPJO 4DBMBྺϲ݄͙Β͍ɺ
    +BWBະܦݧ

    View full-size slide

  3. 2017/11/11 © ChatWork All rights reserved. 3
    $IBU8PSLʹ͍ͭͯ
    ‣ ϏδωενϟοταʔϏε
    ‣ λεΫ؅ཧɾϏσΦ௨࿩
    ‣ ಋೖاۀ ࣾҎ্

    View full-size slide

  4. 2017/11/11 © ChatWork All rights reserved. 4
    5PQJDT
    ‣ $IBU8PSLͰͷ4DBMBͷऔΓ૊Έ
    ‣ 4DBMBϓϩμΫτ΁ͷࢀՃɻֶशͷ͖᪴ͱղܾํ๏
    ‣ 4DBMBΤϯδχΞʹస਎ͯ͠Έͨ݁Ռ

    View full-size slide

  5. 2017/11/11 © ChatWork All rights reserved. 5
    $IBU8PSLͱ4DBMBͷؔ܎ɾ։ൃܦҢ

    View full-size slide

  6. 2017/11/11 © ChatWork All rights reserved. 6
    1)1։ൃ͔Β4DBMB։ൃ΁
    ‣ ೥ࠒ͔Β1)1͚ͩͰͳ͘4DBMBϓϩμΫτ΋։ൃ
    ‣ 4DBMBϓϩμΫτͷ૿Ճ
    ‣ 0"VUI
    ‣ 8FCIPPL
    ‣ #PY࿈ܞ
    ‣ *'555࿈ܞ

    View full-size slide

  7. 2017/11/11 © ChatWork All rights reserved. 7
    $IBU8PSLͱ4DBMBͷؔ܎
    ‣ $IBU8PSLͷ4DBMB࠾༻ϓϩμΫτl'BMDPOzϦϦʔε·Ͱͷࣦഊͱ
    ੒ޭͷྺ࢙ 4DBMB.BUTVSJ

    w IUUQTTQFBLFSEFDLDPNKJLPIJTUPSZPGGBMDPOUIFXBZUPQSPEVDUJPOSFMFBTF
    ‣ $IBU8PSLͷ৽ϝοηʔδϯάγεςϜΛࢧ͑Δٕज़ "84%FW
    %BZ5PLZP

    w IUUQTTQFBLFSEFDLDPNKJLPDIBUXPSLGBMTFYJONFUVTF[JOHVTJTVUFNVXP[IJ
    FSVKJTIV
    ‣ 4DBMBBOE"LLBBQQTPO,VCFSOFUFTJO$IBU8PSL 4DBMBؔ੢
    4VNNJU

    w IUUQTTQFBLFSEFDLDPNIBZBTTIJTDBMBBOEBLLBBQQTPOLVCFSOFUFTJO
    DIBUXPSL

    View full-size slide

  8. 2017/11/11 © ChatWork All rights reserved. 8
    4DBMBϓϩμΫτ΁ͷࢀՃ
    ֶशͷ͖᪴ͱղܾ๏

    View full-size slide

  9. 2017/11/11 © ChatWork All rights reserved. 9
    4DBMBϓϩδΣΫτͰ࢖ΘΕ͍ͯͨ஌ࣝ
    ͱֶशঢ়گ
    ‣ ࢖ΘΕ͍ͯͨϥΠϒϥϦͱݴޠͷဃ཭
    w TDBMB[ "LLB LBNPO DJSDF FUDʜ
    ‣ ࠓ·Ͱܦݧͨ͠ϓϩάϥϛϯάݴޠ
    w 1)1ɺ1ZUIPOɺ$ʜ

    View full-size slide

  10. 2017/11/11 © ChatWork All rights reserved. 10
    1)1ˠ4DBMBֶशͷ݁Ռ

    View full-size slide

  11. 2017/11/11 © ChatWork All rights reserved. 11
    *'555࿈ܞΛ4DBMBͰ։ൃˍϦϦʔε
    ‣ ࢖༻ͯ͠ΔϥΠϒϥϦ
    w "LLB)UUQ
    w "LLB4USFBN
    w TDBMB[
    w DJSDF
    w FUD

    View full-size slide

  12. 2017/11/11 © ChatWork All rights reserved. 12
    *'555࿈ܞ
    ެࣜυΩϡϝϯτ
    IUUQTQMBUGPSNJGUUUDPNEPDT

    View full-size slide

  13. 2017/11/11 © ChatWork All rights reserved. 13
    4DBMBϓϩμΫτʹࢀՃ

    View full-size slide

  14. 2017/11/11 © ChatWork All rights reserved. 14
    େ͖ͳน ϓϩμΫτίʔυͱ஌ࣝͷဃ཭

    def create(implicit scheduler: Scheduler):
    Flow[CreateUserAccountRequest, CreateUserAccountResponse, NotUsed] =
    Flow[CreateUserAccountRequest].mapAsync(1) { userAccount =>
    (for {
    id <- userIdGenerator.generateId()
    result <- userRepository.store(
    UserAccount(
    id,
    Status.Active,
    EmailAddress(userAccount.emailAddress),
    HashedPassword(userAccount.password),
    userAccount.firstName,
    userAccount.lastName,
    Clock.now,
    None
    )
    )
    } yield CreateUserAccountResponse(id.value)).runAsync
    }

    View full-size slide

  15. 2017/11/11 © ChatWork All rights reserved. 15
    େ͖ͳน ϓϩμΫτίʔυͱ஌ࣝͷဃ཭

    def create(implicit scheduler: Scheduler):
    Flow[CreateUserAccountRequest, CreateUserAccountResponse, NotUsed] =
    Flow[CreateUserAccountRequest].mapAsync(1) { userAccount =>
    (for {
    id <- userIdGenerator.generateId()
    result <- userRepository.store(
    UserAccount(
    id,
    Status.Active,
    EmailAddress(userAccount.emailAddress),
    HashedPassword(userAccount.password),
    userAccount.firstName,
    userAccount.lastName,
    Clock.now,
    None
    )
    )
    } yield CreateUserAccountResponse(id.value)).runAsync
    }

    View full-size slide

  16. 2017/11/11 © ChatWork All rights reserved. 16
    ͳͥ೉͘͠ײͨ͡ͷ͔
    ‣ 4DBMB͓Αͼؔ਺ܕݴޠʹ׳Ε͍ͯͳ͍
    w লུه๏ɺߴ֊ؔ਺ɺ҉໧ͷύϥϝʔλɺΧϦʔԽɺFUDʜ
    ‣ +BWBपΓͷ஌ࣝ
    ‣ ετϦʔϛϯάɺฒߦॲཧʹؔ͢Δ஌ࣝ

    View full-size slide

  17. 2017/11/11 © ChatWork All rights reserved. 17
    1)1ͱ4DBMBͷൺֱ
    1)1 4DBMB
    ܕ෇͚ ಈత ੩త
    ϓϩάϥϜύϥμΠϜ
    खଓ͖ܕ
    ΦϒδΣΫτࢦ޲
    ؔ਺ܕ
    ΦϒδΣΫτࢦ޲
    ӨڹΛड͚ͨݴޠ 1FSM $ +BWB
    IUUQTKBXJLJQFEJBPSHXJLJϓϩάϥϛϯάݴޠͷൺֱ

    View full-size slide

  18. 2017/11/11 © ChatWork All rights reserved. 18

    ؔ਺ͷهड़ελΠϧ͕ෳ਺͋Δ
    // ܕΞϊςʔγϣϯΛ࢖͏
    val toInt: (String => Int) = (s: String) => s.toInt
    // ܕΞϊςʔγϣϯΛলུ((Ҿ਺) => ຊମ)
    val toInt2 = (s: String) => s.toInt
    // ϓϨʔεϗϧμʔΛ࢖༻ͨ͠ܗ
    val toInt3: (String => Int) = _.toInt
    w FY
    TUSJOHΛҾ਺ʹͱͬͯɺJOUʹมߋ͢Δؔ਺ͷهड़ελΠϧʹͯ͠΋਺ύλʔϯ͋ΔΑ͏
    ʹࢥ͑ͨ
    w 1)1ͷ৔߹
    w 4DBMBͷ৔߹
    $toInt = function(string $s) {return (int)$s;};
    ‣ ࢀߟ
    w IUUQTHJTUHJUIVCDPNHBLV[[[[
    w IUUQTRJJUBDPNOFTIFFQJUFNTBFDFFGEG

    View full-size slide

  19. 2017/11/11 © ChatWork All rights reserved. 19

    ؔ਺ܕ
    ‣ FY
    UP·Ͱͷ੔਺Ͱۮ਺ͷ΋ͷ͚ͩ ح਺͸আ͘
    Λഒͯ͠ɺ
    ͦͷ૯࿨ΛٻΊΔ
    w 1)1ͷ৔߹
    // ᶃarray_**ܥͷؔ਺Λ࢖ͬͨ৔߹
    $result = array_sum(

    array_map(
    function ($i) {

    return $i * 10;

    },

    array_filter(range(1, 10), function ($i) {

    return ($i % 2 === 0);

    })

    )

    );
    // ᶄ݁ہ͜͏ͳΓͦ͏

    $result = 0;

    foreach (range(1, 10) as $int) {

    if ($int % 2 === 0) {

    $result += $int * 10;

    }

    }

    View full-size slide

  20. 2017/11/11 © ChatWork All rights reserved. 20

    ؔ਺ܕ
    def stringMatching(matcher: (String) => Boolean) = matcher("sample text")
    def stringStart(query: String) =
    stringMatching(_.startsWith(query))
    // ҎԼͱಉٛ
    // strMatching((str: String) => str.startsWith(query))
    def stringContain(query: String) =
    stringMatching(_.contains(query))
    ‣ 4DBMBͷ৔߹ ϫϯϥΠφʔͰهड़Մೳ

    ‣ ଞͷྫɿ4USJOHΛҾ਺ʹͱΓɺCPPMFBOΛฦؔ͢਺Λ౉͢
    (1 to 10).withFilter(_ % 2 == 0).map(_ * 10).sum

    View full-size slide

  21. 2017/11/11 © ChatWork All rights reserved. 21
    +BWBपΓͷ஌ࣝ
    ‣ OVMM΁ͷߟྀ
    w /VMM1PJOUFS&YDFQUJPO͕ൃੜͯ͠͠·͏
    w SFUVSOWBMVFPSOVMMͷ+BWBϝιουΛݺͼग़࣌͢ʹ͸0QUJPOBQQMZͰғͬͯ͋
    ͛Δ
    ‣ +BWBϥΠϒϥϦɺύοέʔδͷཧղ
    w MPHCBDLɺKBWBYDSZQUP
    w εϨουϓʔϧͷ෼ׂ
    ‣ FUDʜ
    akka {
    dispatcher {
    type = Dispatcher
    executor = "thread-pool-executor"
    thread-pool-executor {
    fixed-pool-size = 32
    }
    throughput = 1
    }
    }

    View full-size slide

  22. 2017/11/11 © ChatWork All rights reserved. 22
    ղܾํ๏
    ‣ ஈ֊తʹֶΜͰ͍͘ Ұ౓ʹଟ͘ͷ͜ͱΛֶ͹ͳ͍

    ‣ ݱঢ়ࠔ೉ͱͳΔཁҼΛ෼ׂͯ͠ ̍ͭͣͭ
    ֶͿ
    w ؔ਺ܕݴޠ
    w "LLBTUSFBN
    w +BWBͷ஌ࣝ
    w FUDʜ

    View full-size slide

  23. 2017/11/11 © ChatWork All rights reserved. 23
    ॻ੶ɾXFC
    ڭࡐͰֶश
    ‣ ݴޠ࢓༷ɺؔ਺ܕ΍ετϦʔϜͷ֓೦ͳͲΛॏ఺తʹֶश
    ‣ XFC্Ͱͷ৘ใ
    w 4DBMBશൠ
    w IUUQTEXBOHPHJUIVCJPTDBMB@UFYU
    w IUUQTHJUIVCDPNIBUFOB)BUFOB5FYUCPPLCMPCNBTUFS
    GPVOEBUJPOPGQSPHSBNNJOHTDBMBNE
    w "LLB4USFBN
    w IUUQTUIJOLJUDPKQBSUJDMF

    View full-size slide

  24. 2017/11/11 © ChatWork All rights reserved. 24
    4DBMB
    ࣾ಺ڭࡐͷ׆༻
    ‣ ԋश՝୊Ͱ࣮ࡍʹखΛಈֶ͔ͭͭ͠श

    View full-size slide

  25. 2017/11/11 © ChatWork All rights reserved. 25
    ࣾ಺ͷϦιʔεΛ׆༻͢Δ
    ‣ ༗ࣝऀʹώΞϦϯάˍϖΞϓϩ
    ‣ 4DBMBઐ༻νϟοτ 4DBMB෦
    ͷ׆༻

    View full-size slide

  26. 2017/11/11 © ChatWork All rights reserved. 26
    श࡞ͰຒΊΔ
    ‣ ΑΓ࣮ફతͳ಺༰ͰϓϩμΫτίʔυͱͷࠩ෼ΛঃʑʹຒΊΔ
    ‣ श࡞
    ՝୊ͷ࣮ࢪ
    w 4DBMB
    ࣾ಺ڭࡐ
    w FY
    1MBZ'SBNFXPSLͷԋश՝୊
    w "LLB
    (SBQI4UBHFΛ࢖༻ͯ͠ϑΝΠϧˠ%#΁ͷ؆୯ͳॲཧ
    w SBNMQBSTFSͷ࡞੒
    w FUD
    ‣ ϥΠϒϥϦ࡞੒ˍΞϓϦέʔγϣϯ։ൃ

    View full-size slide

  27. 2017/11/11 © ChatWork All rights reserved. 27
    ஈ֊Λ౿ΜͰ੒Ռ෺ͷϦϦʔε
    ੒Ռ෺ϦϦʔε
    श࡞՝୊
    4DBMB ݴޠֶश

    ϓϩμΫτࢀՃ
    ࣌ܥྻ

    View full-size slide

  28. 2017/11/11 © ChatWork All rights reserved. 28
    4DBMB։ൃͷײ૝
    ‣ ੩తܕɺؔ਺ܕͷԸܙ
    w 1)1Ͱ͸ػೳ௥ՃʹΑΔςετ΍֬ೝ࡞ۀ͕େม Өڹൣғ͕ݟ͑ʹ͍͘

    w ϞσϦϯάɺϦϑΝΫλ͠΍͍͢
    ‣ ֶश͕ਐΉʹͭΕརศੑΛ࣮ײ
    w ঺հग़དྷͳ͔͚ͬͨͲ
    NBUDIDBTF 'VUVSFɺ&JUIFSɺ0QUJPOɺFUDʜ
    ‣ +BWBͷ๛෋ͳࢿ࢈Λ׆༻Ͱ͖Δ

    View full-size slide

  29. 2017/11/11 © ChatWork All rights reserved. 29
    ·ͱΊ
    ‣ 4DBMBΛֶश͔Βೖͬͯ։ൃग़དྷΔ؀ڥ͕͋Δ
    ‣ ΩϟονΞοϓɺ੒௕ग़དྷΔ؀ڥ͕͋Δ
    ‣ ʮֶशʯˠʮश࡞ʯˠʮϓϩμΫτʯͱ͍ͬͨΑ͏ʹஈ֊Λ౿Ή͜
    ͱ͕Ͱ͖ͨ
    ‣ ඼࣭͕୲อ͞Εอकɾӡ༻͕͠΍͘͢ͳΔ
    ‣ ৽ͨͳߟ͑ΛऔΓೖΕΒΕΔ
    ‣ ੩తɺؔ਺ܕɺඇಉظɺฒߦϓϩάϥϛϯάɺFUDʜ

    View full-size slide

  30. 2017/11/11 © ChatWork All rights reserved. 30
    ҰॹʹνϟοτϫʔΫΛྑ͍͖ͯͨ͘͠
    ͍ΤϯδχΞͷํΛืूʂ
    IUUQTDPSQDIBUXPSLDPNKBSFDSVJUFOHJOFFS

    View full-size slide

  31. 2017/11/11 © ChatWork All rights reserved. 31
    ͝ਗ਼ௌ͋Γ͕ͱ͏ޚ࠲͍·ͨ͠

    View full-size slide