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. 2017/11/11 © ChatWork All rights reserved. 2 ࣗݾ঺հ ‣ $IBU8PSLגࣜձࣾαʔόʔαΠυ։ൃ෦

    ‣ ೖࣾ ݱࡏͰஸ౓೥͙Β͍  ‣ 1)1ΤϯδχΞͱͯ͠ೖࣾ ‣ ࠷ۙ4DBMBϓϩμΫτʹ΋KPJO 4DBMBྺϲ݄͙Β͍ɺ +BWBະܦݧ
  2. 2017/11/11 © ChatWork All rights reserved. 3 $IBU8PSLʹ͍ͭͯ ‣ ϏδωενϟοταʔϏε

    ‣ λεΫ؅ཧɾϏσΦ௨࿩ ‣ ಋೖاۀ ࣾҎ্
  3. 2017/11/11 © ChatWork All rights reserved. 4 5PQJDT ‣ $IBU8PSLͰͷ4DBMBͷऔΓ૊Έ

    ‣ 4DBMBϓϩμΫτ΁ͷࢀՃɻֶशͷ͖᪴ͱղܾํ๏ ‣ 4DBMBΤϯδχΞʹస਎ͯ͠Έͨ݁Ռ
  4. 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
  5. 2017/11/11 © ChatWork All rights reserved. 9 4DBMBϓϩδΣΫτͰ࢖ΘΕ͍ͯͨ஌ࣝ ͱֶशঢ়گ ‣

    ࢖ΘΕ͍ͯͨϥΠϒϥϦͱݴޠͷဃ཭ w TDBMB[ "LLB LBNPO DJSDF FUDʜ ‣ ࠓ·Ͱܦݧͨ͠ϓϩάϥϛϯάݴޠ w 1)1ɺ1ZUIPOɺ$ʜ
  6. 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 }
  7. 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 }
  8. 2017/11/11 © ChatWork All rights reserved. 16 ͳͥ೉͘͠ײͨ͡ͷ͔ ‣ 4DBMB͓Αͼؔ਺ܕݴޠʹ׳Ε͍ͯͳ͍

    w লུه๏ɺߴ֊ؔ਺ɺ҉໧ͷύϥϝʔλɺΧϦʔԽɺFUDʜ ‣ +BWBपΓͷ஌ࣝ ‣ ετϦʔϛϯάɺฒߦॲཧʹؔ͢Δ஌ࣝ
  9. 2017/11/11 © ChatWork All rights reserved. 17 1)1ͱ4DBMBͷൺֱ 1)1 4DBMB

    ܕ෇͚ ಈత ੩త ϓϩάϥϜύϥμΠϜ खଓ͖ܕ ΦϒδΣΫτࢦ޲ ؔ਺ܕ ΦϒδΣΫτࢦ޲ ӨڹΛड͚ͨݴޠ 1FSM $ +BWB IUUQTKBXJLJQFEJBPSHXJLJϓϩάϥϛϯάݴޠͷൺֱ
  10. 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
  11. 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;
 }
 }
  12. 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
  13. 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 } }
  14. 2017/11/11 © ChatWork All rights reserved. 22 ղܾํ๏ ‣ ஈ֊తʹֶΜͰ͍͘

    Ұ౓ʹଟ͘ͷ͜ͱΛֶ͹ͳ͍  ‣ ݱঢ়ࠔ೉ͱͳΔཁҼΛ෼ׂͯ͠ ̍ͭͣͭ ֶͿ w ؔ਺ܕݴޠ w "LLBTUSFBN w +BWBͷ஌ࣝ w FUDʜ
  15. 2017/11/11 © ChatWork All rights reserved. 23 ॻ੶ɾXFC ڭࡐͰֶश ‣

    ݴޠ࢓༷ɺؔ਺ܕ΍ετϦʔϜͷ֓೦ͳͲΛॏ఺తʹֶश ‣ XFC্Ͱͷ৘ใ w 4DBMBશൠ w IUUQTEXBOHPHJUIVCJPTDBMB@UFYU w IUUQTHJUIVCDPNIBUFOB)BUFOB5FYUCPPLCMPCNBTUFS GPVOEBUJPOPGQSPHSBNNJOHTDBMBNE w "LLB4USFBN w IUUQTUIJOLJUDPKQBSUJDMF
  16. 2017/11/11 © ChatWork All rights reserved. 26 श࡞ͰຒΊΔ ‣ ΑΓ࣮ફతͳ಺༰ͰϓϩμΫτίʔυͱͷࠩ෼ΛঃʑʹຒΊΔ

    ‣ श࡞ ՝୊ͷ࣮ࢪ w 4DBMB ࣾ಺ڭࡐ w FY 1MBZ'SBNFXPSLͷԋश՝୊ w "LLB (SBQI4UBHFΛ࢖༻ͯ͠ϑΝΠϧˠ%#΁ͷ؆୯ͳॲཧ w SBNMQBSTFSͷ࡞੒ w FUD ‣ ϥΠϒϥϦ࡞੒ˍΞϓϦέʔγϣϯ։ൃ
  17. 2017/11/11 © ChatWork All rights reserved. 28 4DBMB։ൃͷײ૝ ‣ ੩తܕɺؔ਺ܕͷԸܙ

    w 1)1Ͱ͸ػೳ௥ՃʹΑΔςετ΍֬ೝ࡞ۀ͕େม Өڹൣғ͕ݟ͑ʹ͍͘  w ϞσϦϯάɺϦϑΝΫλ͠΍͍͢ ‣ ֶश͕ਐΉʹͭΕརศੑΛ࣮ײ w ঺հग़དྷͳ͔͚ͬͨͲ NBUDIDBTF 'VUVSFɺ&JUIFSɺ0QUJPOɺFUDʜ ‣ +BWBͷ๛෋ͳࢿ࢈Λ׆༻Ͱ͖Δ
  18. 2017/11/11 © ChatWork All rights reserved. 29 ·ͱΊ ‣ 4DBMBΛֶश͔Βೖͬͯ։ൃग़དྷΔ؀ڥ͕͋Δ

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