polyglot になろう !!

E86b46be0f4e61db6b28becc5493bbab?s=47 januswel
August 05, 2017

polyglot になろう !!

E86b46be0f4e61db6b28becc5493bbab?s=128

januswel

August 05, 2017
Tweet

Transcript

  1. 11.

    ྫ͑͹ C++ ʹ͓͚Δ NVI ΠσΟΦϜ C++ ʹ͓͚Δ RAII ΠσΟΦϜ Eiffel

    ͷܖ໿ʹΑΔઃܭ Objective-C ͷ໋໊نଇ 11
  2. 13.

    NVI ΠσΟΦϜ 13 1 #include <iostream> 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++
  3. 14.

    NVI ΠσΟΦϜ 14 1 #include <iostream> 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++
  4. 15.

    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++
  5. 17.

    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 } Α͋͘Δ ? ྫ ྫ֎͕ඈͿͱ
  6. 18.

    1 template <typename T> 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<int> p(new int); 14 // some procedures 15 16 return 0; 17 } RAII ΠσΟΦϜ 18 from C++ σετϥΫλʔ Ͱղ์ Ϧιʔε֬อͱ ॳظԽΛಉ࣌ʹ ྫ֎͕ඈΜͰ ΋ղ์͞ΕΔ
  7. 19.

    ܖ໿ʹΑΔઃܭ 19 Design by Contract ͋Δίʔυ܈Λ࢖͏ଆ Client ͱ࢖ΘΕΔଆ Supplier Ͱຬͨ͢΂͖ࣄલ৚݅

    Obligations ɺ ࣄޙ৚݅ Benefits ɺෆม৚݅ Invariants Λ໌֬ ʹఆٛ͠ɺಈ࡞ͨ͠ͱ͖ʹνΣοΫͰ͖ΔΑ ͏ʹ͢Δ https://www.eiffel.com/values/design-by-contract/introduction/ from Eiffel
  8. 20.

    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
  9. 21.

    ܖ໿ʹΑΔઃܭ 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
  10. 23.
  11. 30.

    1 #include <string> 2 #include <iostream> 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 ΁ Ϝʔϒ ίϯύΠϧ͸௨Δ͕ Կ΋දࣔ͞Εͳ͍
  12. 31.

    1 let a = "foo"; 2 let b = a;

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

    εςοϓͱͯ͠ᶄ ଎౓ؚΊͨ UX ʹͩ͜Θͬͨ Web αʔϏεΛ૊ΜͰΈΔ όοΫΤϯυ Ruby / Golang

    etc ϑϩϯτΤϯυ JavaScript React Native ͰωΠςΟϒػೳΛ࢖ͬͨϞόΠϧΞϓϦ Λ࡞ͬͯΈΔ JavaScript + Objective-C / Java (+ Swift / Kotlin) 42