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

Functional programming - part 2

Yejun Su
January 03, 2023

Functional programming - part 2

Applying the skill "Distinguish Actions, Calculations and Data".
See part 1 for some background knowledge.

Yejun Su

January 03, 2023
Tweet

More Decks by Yejun Su

Other Decks in Programming

Transcript

  1. Functional programming
    James Su - 2022/05/27
    Sur
    f
    ing in the changing world

    View Slide

  2. Re-learn


    Actions, Calculations and Data

    View Slide

  3. Glossary
    • Actions - Functions with side e
    ff
    ects


    • A
    ff
    ected by when and how many times they are called.


    • Calculations - functions without any side e
    ff
    ects


    • Given the same input, returns the same output.


    • Data - facts about events


    • Immutable in functional programming languages


    • Can be immutable in object-oriented programming languages

    View Slide

  4. Analogy
    for information system

    View Slide

  5. Usage
    • Thinking a problem before coding


    • Coding a solution


    • Reading existing code

    View Slide

  6. Use case - Pending Emails

    View Slide

  7. Reading code
    • Look for Actions because they need the most attention.


    • Find code smell without running code.

    View Slide

  8. Reading code

    View Slide

  9. Thinking a problem before coding
    • What data we will need to capture (Data)


    • What decisions we will need to make (Calculations)


    • Clarifying problems needs attention (Actions)

    View Slide

  10. Thinking a problem

    View Slide

  11. Coding a solution
    • Changeability: Actions > Calculations > Data.


    • Few Actions, more Calculations and Data.

    View Slide

  12. Coding a solution

    View Slide

  13. Solution

    View Slide

  14. Re-learn


    Strati
    f
    ied design

    View Slide

  15. Strati
    f
    ied design
    A technique for building
    software in layers.

    View Slide

  16. What is software design?
    "using one’s aesthetic sense to guide
    programming choices to improve the ease of
    coding, testing, and maintaining software"

    View Slide

  17. How strati
    f
    ied design help us
    to develop aesthetic senses
    • Straightforward implementation


    • Abstraction barrier


    • Minimal interface


    • Comfortable layers

    View Slide

  18. Straightforward implementation

    View Slide

  19. Call graph
    • Arrows represent function calls


    • Functions are in di
    ff
    erent layers
    Visualizing our function calls

    View Slide

  20. Straightforward
    call functions from similar layers of abstraction

    View Slide

  21. Straightforward
    all functions in a layer should serve the same purpose

    View Slide

  22. Problems
    may exist in three levels
    • Interaction between layers


    • Implementation of one layer


    • Implementation of one function

    View Slide

  23. Use call graph
    • Global zoom level


    • Layer zoom level


    • Function zoom level
    to
    f
    ind problems in di
    ff
    erent levels

    View Slide

  24. Call graph practice
    Pending Emails

    View Slide

  25. Q & A

    View Slide