3.3 Reactive Programming
Reactive programming is an elegant and powerful programming paradigm, but it can be disorienting at first because it’s a very different paradigm to writing a script. ~Hadley Wickham (Author)
Mental Model
- tell vs inform (providing Shiny with recipes, not giving it commands).
- recipes, not commands.
3.3.1 Imperative vs declarative programming
Key differences between two important styles of programming:
Imperative programming - issue a specific command and it’s carried out immediately.
Declarative programming - express higher-level goals or describe important constraints, and rely on someone else to decide how and/or when to translate that into action.
Imperative code is assertive; declarative code is passive-aggressive
“Make me a sandwich” vs “Ensure there is a sandwich in the refrigerator whenever I look inside of it”
In essence, you describe your overall goals, and the software figures out how to achieve them without further intervention.