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

JSNation 2019: Stop the Software Apocalypse with Functional Programming

JSNation 2019: Stop the Software Apocalypse with Functional Programming

With the rise of software-based innovation, the business rules and flow controls are getting more complex. Software engineers do not only have to handle increasingly complicated problems, but they also carry greater responsibility for ensuring the quality of their code.

It’s clear that our tools and methods should evolve to build robust software. In this talk, we’ll explore how to leverage functional programming techniques to reduce the complexity and write safer JavaScript in a real-world scenario. Come to see what’s exciting about static analysis, pure functions, composition and immutability; and how these principles are a powerful tool to optimize your code for correctness.

053151a066bcaecbc1480644d7cbd1e1?s=128

Fernanda Andrade

June 07, 2019
Tweet

Transcript

  1. Stop the Software Apocalypse with Functional Programming

  2. Somers, J. (2017). The Coming Software Apocalypse. The Atlantic.

  3. None
  4. None
  5. Reduce complexity with pure functions

  6. Mutability let counter = x + 3; // counter =

    7 console.log(counter + x); // 25
  7. let counter = x + 3; // counter = 7

    console.log(counter + x); // 25 Where is x changing? Side effects
  8. ?

  9. No side effects function getX(value) { return value + 2;

    } getX(2); // 4 getX(5); // 7
  10. function getX(value) { return value + 2; } getX(2); //

    4 getX(5); // 7 No mutation Different input
  11. Optimize for correctness

  12. Tests describe("...", function() { beforeEach(function() { // prepare the state

    }); context("when...", function() { it("returns...", function() { // expects something }); }); afterEach(function() { // clean the state }); });
  13. Tests describe("...", function() { context("when value is 2", function() {

    it("returns...", function() { return expect(getX(2)).to.be.equal(4); }); }); });
  14. Types function changeProperty(property) { return property.toUpperCase(); } const user =

    { name: "Joe", age: 50 };
  15. Types function changeProperty(property) { return property.toUpperCase(); } const user =

    { name: "Joe", age: 50 }; changeProperty(user.email)
  16. Types changeProperty(user.email)

  17. Types interface User { name: string; age: number; } function

    changeProperty(property: string): string { return property.toUpperCase(); } const user: User = { name: "Joe", age: 50 }
  18. Types changeProperty(user.email)

  19. Structure our systems to be more comprehensible

  20. Thank you! @feru