$30 off During Our Annual Pro Sale. View Details »

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.

Fernanda Andrade

June 07, 2019
Tweet

More Decks by Fernanda Andrade

Other Decks in Programming

Transcript

  1. Stop the Software
    Apocalypse with
    Functional Programming

    View Slide

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

    View Slide

  3. View Slide

  4. View Slide

  5. Reduce complexity
    with pure functions

    View Slide

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

    View Slide

  7. let counter = x + 3;
    // counter = 7
    console.log(counter + x);
    // 25
    Where is x
    changing?
    Side effects

    View Slide

  8. ?

    View Slide

  9. No side effects
    function getX(value) {
    return value + 2;
    }
    getX(2);
    // 4
    getX(5);
    // 7

    View Slide

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

    View Slide

  11. Optimize for
    correctness

    View Slide

  12. Tests
    describe("...", function() {
    beforeEach(function() {
    // prepare the state
    });
    context("when...", function() {
    it("returns...", function() {
    // expects something
    });
    });
    afterEach(function() {
    // clean the state
    });
    });

    View Slide

  13. Tests
    describe("...", function() {
    context("when value is 2", function() {
    it("returns...", function() {
    return expect(getX(2)).to.be.equal(4);
    });
    });
    });

    View Slide

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

    View Slide

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

    View Slide

  16. Types
    changeProperty(user.email)

    View Slide

  17. Types
    interface User {
    name: string;
    age: number;
    }
    function changeProperty(property: string): string {
    return property.toUpperCase();
    }
    const user: User = {
    name: "Joe",
    age: 50
    }

    View Slide

  18. Types
    changeProperty(user.email)

    View Slide

  19. Structure our
    systems to be more
    comprehensible

    View Slide

  20. Thank you!
    @feru

    View Slide