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

I can haz no Futures?

I can haz no Futures?

You will learn how simple functional patterns can be used to make your business logic cleaner and more testable.

Asynchronous programming brings a lot of Futures to your code. Bad news is that they are not essential to what your application really does… You end up with Futures of assertions in your unit tests or, even worse, with Await or expectNoMsg calls.

This is a live coding talk. First I will code an application using Futures in both business logic and unit tests. Then I will get rid of Futures without losing asynchronicity. In the second part, I will do a step by step refactoring of a simple Akka actor system. In both cases I will use typeclasses from Cats library.

Michał Płachta

November 09, 2016
Tweet

More Decks by Michał Płachta

Other Decks in Programming

Transcript

  1. I can haz no
    Futures?
    Michał Płachta
    @miciek

    View Slide

  2. The Journey Ahead of Us
    WHY?
    REFACTORING
    ACTOR SYSTEM
    REFACTORING
    ADD FUNCTION

    View Slide

  3. Complexity is the
    root cause of the
    vast majority of
    problems with
    software today.

    View Slide

  4. Essential
    ▪ The “heart” of your
    system
    ▪ The WHAT
    Complexity
    Accidental
    ▪ The least important part
    of your system
    ▪ The HOW and WHEN

    View Slide

  5. Future[Option[Customer]]
    Here’s a return type of a function in a CRM system...
    QUIZ
    Accidental Complexity Essential Complexity

    View Slide


  6. We have to keep it
    crisp, disentangled,
    and simple if we
    refused to be crushed
    by the complexities of
    our own making…
    Portrait by Hamilton Richards - manuscripts of Edsger W. Dijkstra, University Texas at Austin, CC BY-SA
    3.0, https://commons.wikimedia.org/w/index.php?curid=4204157

    View Slide

  7. Managing
    Complexity
    Live coding examples

    View Slide

  8. def add(Int, Future[Int]): Future[Int]
    Let’s start with a very simple case...
    LIVE CODING #1

    View Slide

  9. Palindrome
    Checker
    Actor
    Length
    Calculator
    Actor
    String Stats
    Calculator
    Actor
    def stringStats(String): Future[StringStats]
    External Stuff We Can’t Touch
    LIVE CODING #2

    View Slide

  10. ANY QUESTIONS?
    @miciek
    www.michalplachta.com/contact
    Thanks!

    View Slide