SlideShare a Scribd company logo
Declarative Magic
Introduction
Feather Knee. Yes! It’s my real name!

@featherart
Declarative vs Imperative
Both are programming paradigms
Wait, paradigm?
noun, 15th c.
1. A typical example or pattern of something, or an
archetype.

Synonyms: model, template, example
Programming Paradigm
• A pattern for organizing code, either by execution
model, or by state 

• Sometimes, but not always, language-specific
Some Paradigms
• Imperative

• Functional

• Declarative

• Object-oriented

• Procedural
Pop Quiz!
JavaScript can be used with the following paradigm:

A. Procedural

B. Object-oriented

C. Functional

D. All of the above
Pop Quiz!
JavaScript can be used with the following paradigm:

A. Procedural

B. Object-oriented

C. Functional

D. All of the above
Such Flexible!
Practical foundations, the duct tape of languages
🎉🎉🎉
Q: Best Way?
A: It depends
Different Goals
Speed of execution 🏁

Efficient use of resources 🌵

Readability & ease of testing 👀
React
• Declarative by design

• Not first to have that idea
Declarative
Logic of computation without description of control flow
Imperative
Use of statements to change a program’s state
Explicit control over flow
Sum an Array
Imperatively
Sum an Array
Declaratively
Elegant vs/ clever
Better Way?
• Both have same approximate runtime 🏁

• One is easier to read 👀
Q: How do I know
They have approximately the same runtime?
A: Big O Analysis
Under the hood, they both use a for-loop
Iterate through an Array of N elements -> O(N)
Big O Analysis
Runtimes of algorithms
Big O Analysis
O (N)
+- O (N)
Loose is ok
Clean, readable code may leave yak slightly hairy!
But this is still bad
Still a triple loop, even if you’re using Array methods
O(N)
O(N)
O(N)
O(N^3)
Unique an Array
Imperatively
Unique an Array
Declaratively
Big O?
O(1)
O(N)
Why So Speedy?
Under the covers Set uses a Hash, so constant lookup!
3 Array Methods
.filter() => Array

.map() => Array

.reduce() => *
Pop Quiz!
One of these almost became another Array method:

A. .squiggle()

B. .slurp()

C. .smoosh()

D. None of the above
Pop Quiz!
One of these almost became another Array method:

A. .squiggle()

B. .slurp()

C. .smoosh()
D. None of the above
3 Array Methods
.filter() => Array

.map() => Array

.reduce() => *
Suppose you are …
The sorting hat for a day
Filter
Imperatively
Filter
Declaratively
3 Array Methods
.filter() => Array

.map() => Array

.reduce() => *
Suppose you just …
Get really excited about things for no apparent reason!!!
Map
Imperatively
Map
Declaratively
Fun Fact
If you do a lot of React, map() will be your new BFF
mapping JSX elements onto an Array…
Map!
JQuery
• Direct manipulation of DOM elements

• Every change in state is a refresh
React
DOM never gets touched directly

Focus on how UI should look at any given moment
vs. how to change it over time (state)
Changing State
key difference!
paradigm: pattern for organizing code, either by execution model, or by state
What is State?
• State of an application = the current value of any variables

• Logged in to your bank account: currentUser = “Your Name”
Imperative UI
Direct manipulation of DOM elements to reflect
changes in state
The horrors of old time string concatenation before we got template strings in ES6.
Much
appending!
Declarative UI
Never directly touch DOM elements
The horrors of old time string concatenation before we got template strings in ES6.
set state
DOM
reflects
change
To Summarize
Declarative in general describes what, now how

Set state to update DOM

Goal of readability
Further ?s/comments
Come see me on break! 

Reach out on Twitter @featherart

I also wrote a Medium story plus GitHub repo with
code samples https://goo.gl/H2FpJ4

More Related Content

Similar to Declarativemagic

All of Javascript
All of JavascriptAll of Javascript
All of Javascript
Togakangaroo
 
tutorial.ppt
tutorial.ppttutorial.ppt
tutorial.ppt
GuioGonza2
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
Dibyendu Tiwary
 
Word_Embeddings.pptx
Word_Embeddings.pptxWord_Embeddings.pptx
Word_Embeddings.pptx
GowrySailaja
 
JavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes YouJavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes You
Scott Kosman
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
mircodotta
 
Advanced Programming Techniques
Advanced Programming TechniquesAdvanced Programming Techniques
Advanced Programming Techniques
Gary Stark
 
All of javascript
All of javascriptAll of javascript
All of javascript
Togakangaroo
 
Threading Is Not A Model
Threading Is Not A ModelThreading Is Not A Model
Threading Is Not A Model
guest2a5acfb
 
Leveling Up at JavaScript
Leveling Up at JavaScriptLeveling Up at JavaScript
Leveling Up at JavaScript
Raymond Camden
 
The productivity brought by Clojure
The productivity brought by ClojureThe productivity brought by Clojure
The productivity brought by Clojure
Laurence Chen
 
Hotfixing iOS apps with Javascript
Hotfixing iOS apps with JavascriptHotfixing iOS apps with Javascript
Hotfixing iOS apps with Javascript
Sergio Padrino Recio
 
Assign
AssignAssign
Assign
EMSNEWS
 
Four Languages From Forty Years Ago
Four Languages From Forty Years AgoFour Languages From Forty Years Ago
Four Languages From Forty Years Ago
Scott Wlaschin
 
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better PartsJS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better Parts
JSFestUA
 
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Praveen Kumar
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
Aly Abdelkareem
 
PARADIGM IT.pptx
PARADIGM IT.pptxPARADIGM IT.pptx
PARADIGM IT.pptx
jamesmarken1
 
Presentation
PresentationPresentation
Presentation
pnathan_logos
 

Similar to Declarativemagic (20)

All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
tutorial.ppt
tutorial.ppttutorial.ppt
tutorial.ppt
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
 
Word_Embeddings.pptx
Word_Embeddings.pptxWord_Embeddings.pptx
Word_Embeddings.pptx
 
JavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes YouJavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes You
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
Advanced Programming Techniques
Advanced Programming TechniquesAdvanced Programming Techniques
Advanced Programming Techniques
 
All of javascript
All of javascriptAll of javascript
All of javascript
 
Threading Is Not A Model
Threading Is Not A ModelThreading Is Not A Model
Threading Is Not A Model
 
Leveling Up at JavaScript
Leveling Up at JavaScriptLeveling Up at JavaScript
Leveling Up at JavaScript
 
The productivity brought by Clojure
The productivity brought by ClojureThe productivity brought by Clojure
The productivity brought by Clojure
 
Hotfixing iOS apps with Javascript
Hotfixing iOS apps with JavascriptHotfixing iOS apps with Javascript
Hotfixing iOS apps with Javascript
 
Assign
AssignAssign
Assign
 
Four Languages From Forty Years Ago
Four Languages From Forty Years AgoFour Languages From Forty Years Ago
Four Languages From Forty Years Ago
 
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better PartsJS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better Parts
 
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
PARADIGM IT.pptx
PARADIGM IT.pptxPARADIGM IT.pptx
PARADIGM IT.pptx
 
Presentation
PresentationPresentation
Presentation
 

Recently uploaded

Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 

Recently uploaded (20)

Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 

Declarativemagic