Applying the skill "Distinguish Actions, Calculations and Data". See part 1 for some background knowledge.
Functional programmingJames Su - 2022/05/27Surfing in the changing world
View Slide
Re-learnActions, Calculations and Data
Glossary• Actions - Functions with side effects• Affected by when and how many times they are called.• Calculations - functions without any side effects• 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
Analogyfor information system
Usage• Thinking a problem before coding• Coding a solution• Reading existing code
Use case - Pending Emails
Reading code• Look for Actions because they need the most attention.• Find code smell without running code.
Reading code
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)
Thinking a problem
Coding a solution• Changeability: Actions > Calculations > Data.• Few Actions, more Calculations and Data.
Coding a solution
Solution
Re-learnStratified design
Stratified designA technique for buildingsoftware in layers.
What is software design?"using one’s aesthetic sense to guideprogramming choices to improve the ease ofcoding, testing, and maintaining software"
How stratified design help usto develop aesthetic senses• Straightforward implementation• Abstraction barrier• Minimal interface• Comfortable layers
Straightforward implementation
Call graph• Arrows represent function calls• Functions are in different layersVisualizing our function calls
Straightforwardcall functions from similar layers of abstraction
Straightforwardall functions in a layer should serve the same purpose
Problemsmay exist in three levels• Interaction between layers• Implementation of one layer• Implementation of one function
Use call graph• Global zoom level• Layer zoom level• Function zoom leveltofind problems in different levels
Call graph practicePending Emails
Q & A