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

Rock-Solid JavaScript through Applied Science

Dierk König
October 17, 2019

Rock-Solid JavaScript through Applied Science

Many of our Java application have JavaScript frontends. While the Java part of the application is considered to be well engineered, the JavaScript part often lacks industrial-strength stability. This talk shows new ways to make your JavaScript code more reliable - not by introducing new frameworks or libraries but by doing less, going back to the basics, and leveraging the science behind the lambda calculus.

Dierk König

October 17, 2019
Tweet

More Decks by Dierk König

Other Decks in Science

Transcript

  1. 2 Dierk König Fellow at Karakun Prof at FHNW @mittie

    @ProfDKoenig https://dierk.github.io/Home
  2. #FUB3FEVDUJPO GYG Y  JE    YJE Y

       JE   YY    
  3. "UPNJD-BNCEB5FSNT // atoms const id = x => x; const

    fst = x => y => x; const snd = x => y => y;
  4. 1BJS // atoms const id = x => x; const

    fst = x => y => x; const snd = x => y => y; const Pair = x => y => accessor => accessor(x)(y);
  5. 1BJS$SFBUJPO // atoms const id = x => x; const

    fst = x => y => x; const snd = x => y => y; const Pair = x => y => accessor => accessor(x)(y); const point = Pair(1024)(200);
  6. 1BJS"DDFTT // atoms const id = x => x; const

    fst = x => y => x; const snd = x => y => y; const Pair = x => y => accessor => accessor(x)(y); const point = Pair(1024)(200); point(fst); // 1024, compare to pair.fst point(snd); // 200, compare to pair.snd the basic product type
  7. 5VQMFT6TBHF const [Person, firstname, lastname, age] = Tuple(3); const dierk

    = Person('Dierk')('König')(51); dierk(firstname); // 'Dierk', compare to dierk.firstname
  8. &JUIFS $P1SPEVDU 4VN const Left = x => f =>

    g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => f => g => e(f)(g); // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( msg => console.log(msg) ) ( res => id(res) ) η-reduce
  9. 3FGBDUPSJOH"MHFCSB const Left = x => f => g =>

    f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => f => g => e(f)(g); // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id ) η-reduce
  10. 3FGBDUPSJOH"MHFCSB const Left = x => f => g =>

    f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => f => e(f) ; // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id ) η-reduce
  11. &JUIFS $P1SPEVDU 4VN const Left = x => f =>

    g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = e => e ; // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id ) definition
  12. &JUIFS $P1SPEVDU 4VN const Left = x => f =>

    g => f(x); // ctor 1 const Right = x => f => g => g(x); // ctor 2 const either = id ; // accessor const safeDiv = x => y => y === 0 ? Left ("divisor is zero") : Right(x / y); either ( safeDiv(1)(0) ) ( console.log ) ( id )
  13. 3FBM8PSMEVTBHF8FC4IPQ1BZNFOU0QUJPOT const [Cash, CreditCard, Transfer, match] = Choice(3); // generalized

    sum type const pay = payment => match(payment) ( () => amount => 'pay ' + amount + ' cash') ( ( { number, sec } ) => amount => 'pay ' + amount + ' with credit card ' + number + ' / ' + sec) ( ( [ from, to ] ) => amount => 'pay ' + amount + ' by wire from ' + from + ' to ' + to); let payment = Cash(); assert.is( pay(payment)(50), 'pay 50 cash'); payment = CreditCard( { number: '0000 1111 2222 3333', sec: '123' } ); assert.is( pay(payment)(50), 'pay 50 with credit card 0000 1111 2222 3333 / 123'); payment = Transfer(['Account 1', 'Account 2']); assert.is( pay(payment)(50), 'pay 50 by wire from Account 1 to Account 2');
  14. Karakun AG Elisabethenanlage 25 4051 Basel Switzerland T. E. W.

    +41 61 551 36 36 [email protected] www.karakun.com Gerne beraten und schulen wir auch Sie dabei, welche Technologien sie am besten einsetzen und wie sie ihre Software-Entwicklung verbessern können. Wir freuen uns auf Ihre Kontaktaufnahme!