Slide 1

Slide 1 text

polyglot ʹͳΖ͏ !! builderscon 2017 8/5 by januswel 1

Slide 2

Slide 2 text

͠Ό΂Δͻͱ januswel ΍͵͢ ޷͖ͳݴޠ C++ JavaScript React Native Japan react-native-router-flux react-native-sound 2 janus_wel januswel

Slide 3

Slide 3 text

͠Ό΂Δ͜ͱ polyglot ͱ͸ ? polyglot ͷϝϦοτ polyglot ʹͳΔʹ͸ 3

Slide 4

Slide 4 text

polyglot ͱ͸ ? 4

Slide 5

Slide 5 text

polyglot ͱ͸ ? 5

Slide 6

Slide 6 text

polyglot ͱ͸ ? 6 > ໊ࢺ > ਺͔ࠃޠʹ௨͡Δਓ; ਺͔ࠃޠͰॻ͍ͨ ຊ[੟ॻ]; ଟݴޠͷࠞަ

Slide 7

Slide 7 text

polyglot ͱ͸ ? 7 సͯ͡ ϓϩάϥϜݴޠΛෳ਺ѻ͑Δͻͱ ͱ͍͏ҙຯͰ࢖ΘΕΔ

Slide 8

Slide 8 text

polyglot ͷϝϦοτ 8

Slide 9

Slide 9 text

͔͍͍ͬ͜ 9

Slide 10

Slide 10 text

͋Δݴޠͷ֓೦Λผݴޠ ʹ࣋ͪࠐΉ͜ͱ͕Ͱ͖Δ 10

Slide 11

Slide 11 text

ྫ͑͹ C++ ʹ͓͚Δ NVI ΠσΟΦϜ C++ ʹ͓͚Δ RAII ΠσΟΦϜ Eiffel ͷܖ໿ʹΑΔઃܭ Objective-C ͷ໋໊نଇ 11

Slide 12

Slide 12 text

NVI ΠσΟΦϜ 12 Non Virtual Interface public ͳϝϯόʔؔ਺ΛԾ૝ؔ਺ͱ͠ͳ͍ઃܭ from C++

Slide 13

Slide 13 text

NVI ΠσΟΦϜ 13 1 #include 2 class Animal { 3 public: 4 virtual ~Animal() { } 5 virtual void greet() const = 0; 6 }; 7 class Dog : public Animal { 8 public: 9 virtual void greet() const { 10 std::cout << "bow wow"; 11 } 12 }; 13 class Cat : public Animal { 14 public: 15 virtual void greet() const { 16 std::cout << "meow"; 17 } 18 }; ΦϒδΣΫτࢦ޲ͷ Α͋͘Δྫ from C++

Slide 14

Slide 14 text

NVI ΠσΟΦϜ 14 1 #include 2 class Animal { 3 public: 4 virtual ~Animal() { } 5 void greet() const { 6 std::cout << call(); 7 } 8 9 protected: 10 virtual char const * call() const = 0; 11 }; 12 class Dog : public Animal { 13 protected: 14 virtual char const * call() const { 15 return "bow wow"; 16 } 17 }; 18 class Cat : public Animal { 19 protected: 20 virtual char const * call() const { 21 return "meow"; 22 } 23 }; greet() Λඇ Ծ૝ؔ਺ʹ Ծ૝ؔ਺ call() Λ௥Ճ from C++

Slide 15

Slide 15 text

NVI ΠσΟΦϜ 15 2 class Animal { 3 public: 4 virtual ~Animal() { } 5 void greet() const { 6 std::cout 7 << call() << "\n" 8 << call() 9 << std::endl; 10 } 11 12 protected: 13 virtual char const * call() const = 0; 14 }; ڞ௨͢ΔৼΔ෣͍Λมߋ͠΍͍͢ 2 ճ໐͘Α͏ ʹมߋ վߦΛ௥Ճ ࢠΫϥεʹ खΛՃ͑ͣ มߋՄೳ !! from C++

Slide 16

Slide 16 text

RAII ΠσΟΦϜ 16 from C++ Resource Acquisition Is Initialization Ϧιʔεͷ֬อͱ։์Λ ΦϒδΣΫτϥΠϑαΠΫϧͰ؅ཧ͢Δ

Slide 17

Slide 17 text

RAII ΠσΟΦϜ 17 from C++ 1 int main(const int argc, const char* const argv[]) { 2 int * const p = new int; 3 // some procedures 4 delete p; 5 6 return 0; 7 } Α͋͘Δ ? ྫ ྫ֎͕ඈͿͱ

Slide 18

Slide 18 text

1 template 2 class Pointer { 3 public: 4 Pointer(T * const pointer) : _pointer(pointer) { } 5 ~Pointer() { 6 delete _pointer; 7 } 8 private: 9 T * const _pointer; 10 }; 11 12 int main(const int argc, const char* const argv[]) { 13 Pointer p(new int); 14 // some procedures 15 16 return 0; 17 } RAII ΠσΟΦϜ 18 from C++ σετϥΫλʔ Ͱղ์ Ϧιʔε֬อͱ ॳظԽΛಉ࣌ʹ ྫ֎͕ඈΜͰ ΋ղ์͞ΕΔ

Slide 19

Slide 19 text

ܖ໿ʹΑΔઃܭ 19 Design by Contract ͋Δίʔυ܈Λ࢖͏ଆ Client ͱ࢖ΘΕΔଆ Supplier Ͱຬͨ͢΂͖ࣄલ৚݅ Obligations ɺ ࣄޙ৚݅ Benefits ɺෆม৚݅ Invariants Λ໌֬ ʹఆٛ͠ɺಈ࡞ͨ͠ͱ͖ʹνΣοΫͰ͖ΔΑ ͏ʹ͢Δ https://www.eiffel.com/values/design-by-contract/introduction/ from Eiffel

Slide 20

Slide 20 text

1 class DICTIONARY [ELEMENT] 2 feature 3 put (x: ELEMENT; key: STRING) is 4 -- Insert x so that it will be retrievable through key. 5 require 6 count <= capacity 7 not key.empty 8 ensure 9 has (x) 10 item (key) = x 11 count = old count + 1 12 end 13 -- ... Interface specifications of other features ... 14 invariant 15 0 <= count 16 count <= capacity 17 end ܖ໿ʹΑΔઃܭ 20 ࣄલ৚݅ ࣄޙ৚݅ ෆม৚݅ from Eiffel

Slide 21

Slide 21 text

ܖ໿ʹΑΔઃܭ 21 in JavaScript 1 export function zeroPadding(n: number, digit: number = 8): string { 2 assert(0 <= n) 3 assert(1 < digit) 4 const zeros = Array(digit - 1).fill('0').join('') 5 return `${zeros}${n.toString()}`.slice(-digit) 6 } 7 8 zeroPadding(32, 3); 9 zeroPadding(-4, 3); ࣄલ৚݅ ࣄલ৚݅ҧ൓ ࣄޙ৚݅΍ෆม৚݅͸ݺͼग़͠ଆͷڠྗ͕ඞཁ͕ͩ assert ͕͋Ε͹ܖ໿ʹΑΔઃܭΛ࣮ݱͰ͖Δ from Eiffel

Slide 22

Slide 22 text

JavaScript ͷ assert ͱܕ http://qiita.com/janus_wel/items/da1fcfc8d50969135b31 assert: unassert https://github.com/unassert-js/unassert ܕ : flow https://flow.org/ 22

Slide 23

Slide 23 text

Objective-C ໋໊نଇ ໌֬ͳ୯ޠΛ࢖͏ do ΍ does ͳͲ࢖Θͳ͍ ୯ޠΛུ͞ͳ͍ ઌ಄Λಈࢺͱ͢Δ etc 23 https://developer.apple.com/jp/documentation/CodingGuidelines.pdf

Slide 24

Slide 24 text

Objective-C ໋໊نଇ will willChangeStatusBarFrame did windowDidMove 24 https://developer.apple.com/jp/documentation/CocoaEncyclopedia.pdf

Slide 25

Slide 25 text

Objective-C ໋໊نଇ componentDidMount componentWillReceiveProps componentWillUpdate componentWillUnmount 25 in React.js

Slide 26

Slide 26 text

ಛఆͷͻͱͭͷݴޠʹ͍ͭͯ ΋ΑΓਂ͍ཧղΛಘΒΕΔ 26

Slide 27

Slide 27 text

ݴޠ΁ͷཧղ͕ਂ·Δ ݴޠΛผࢹ఺ͰோΊΔ͜ͱ͕Ͱ͖ΔͷͰɺ ΑΓཧղ͕ਐΉ C ݴޠͷϙΠϯλʔͱ Java ͷࢀর౉͠ C++ ͷ move semantics ͱ Rust ͷॴ༗ݖ ԋࢉࢠͷ༏ઌॱҐͱ݁߹ੑ 27

Slide 28

Slide 28 text

ϙΠϯλʔ 28 ϝϞϦʔϨΠΞ΢τ্ͷ͋Δ Ұ఺Λࢦࣔ͢͠ͷ͕ϙΠϯλʔ ϙΠϯλʔΛ௨ͯ͡த਎Λࢀ রͰ͖Δ 0x00 0x01 0x02 0xff b u i … \0

Slide 29

Slide 29 text

ࢀর౉͠ 29 b u i … \0 ࢀর౉͠͸ϙΠϯλʔͷଘࡏ Λҙࣝ͠ͳ͍Α͏ʹ͚ͨͩ͠ 0x00 0x01 0x02 0xff

Slide 30

Slide 30 text

1 #include 2 #include 3 4 int main(const int argc, const char* const argv[]) { 5 std::string a = "foo"; 6 std::string b = std::move(a); 7 8 std::cout << a << std::endl; 9 10 return 0; 11 } move semantics 30 a ͔Β b ΁ Ϝʔϒ ίϯύΠϧ͸௨Δ͕ Կ΋දࣔ͞Εͳ͍

Slide 31

Slide 31 text

1 let a = "foo"; 2 let b = a; 3 4 println!(a); ॴ༗ݖ 31 a ͔Β b ΁ॴ༗ݖ ΛҠ͢ ಉ֓͡೦ΛΑΓγϯϓϧʹදݱ͍ͯ͠Δ ίϯύΠϧ Τϥʔ

Slide 32

Slide 32 text

2 ͭΊҎ߱ͷݴޠ͸༰қ ʹशಘͰ͖Δ 32

Slide 33

Slide 33 text

ݴޠशಘ 33 > ݴޠͱ͍͏΋ͷ͸ɺΑͬΆͲͷʮͰ͖ͦ͜ͳ ͍ʯͰͳ͍ݶΓɺ͢Ͱʹ஌͍ͬͯΔݴޠ͔Β؆୯ ʹֶ΂ΔͷͰ͢ Thomas E. Kurtz ݴޠઃܭऀ͕ͨͪߟ͑Δ͜ͱ

Slide 34

Slide 34 text

ݴޠͷߏ੒ཁૉ͸ ࣅ௨͍ͬͯΔ ࣜɾจ ԋࢉࢠ ੍ޚߏจ ؔ਺ / ϝιου ίϝϯτ etc 34

Slide 35

Slide 35 text

৽͍͠ݴޠ͸طଘݴޠ͔Β ӨڹΛड͚͍ͯΔ 35 https://github.com/taisa831/Langury

Slide 36

Slide 36 text

36 Perl ͷܥේ

Slide 37

Slide 37 text

࡞Δ͜ͱͷͰ͖Δ΋ͷͷ ෯͕޿͕Δ 37

Slide 38

Slide 38 text

֤ݴޠ͝ͱʹ ಘҙͳྖҬ͕͋Δ Python: ਺ֶɺػցֶश Ruby: Web αʔϏε JavaScript: ϑϩϯτΤϯυ C++: ήʔϜ etc 38

Slide 39

Slide 39 text

polyglot ʹͳΔʹ͸ 39

Slide 40

Slide 40 text

ίετ ? ΍Δؾ ࣌ؒ 40 ࡞Γ͍ͨ΋ͷ͕͋Ε͹໰୊ʹͳΒͳ͍

Slide 41

Slide 41 text

εςοϓͱͯ͠ᶃ ·ͬͨ͘ผͷྖҬʹखΛग़ͯ͠ΈΔ Web αʔϏεΛ࡞͍ͬͯͨͳΒήʔϜ΍Ϟ όΠϧΞϓϦɺػցֶशɺ IoT ͳͲ 41

Slide 42

Slide 42 text

εςοϓͱͯ͠ᶄ ଎౓ؚΊͨ UX ʹͩ͜Θͬͨ Web αʔϏεΛ૊ΜͰΈΔ όοΫΤϯυ Ruby / Golang etc ϑϩϯτΤϯυ JavaScript React Native ͰωΠςΟϒػೳΛ࢖ͬͨϞόΠϧΞϓϦ Λ࡞ͬͯΈΔ JavaScript + Objective-C / Java (+ Swift / Kotlin) 42

Slide 43

Slide 43 text

·ͱΊ ࡞ΕΔ΋ͷͷ෯͕޿͕Δ ݱࡏ࢖͍ͬͯΔݴޠͷཧղ͕ਂ·Δ ͲΜͲΜָ͘͠ͳΔ 43 polyglot ʹͳΔ͜ͱͰ ͥͻ΍ͬͯΈΑ͏