SlideShare uma empresa Scribd logo
1 de 76
Cameron Presley
@pcameronpresley
Cameron@TheSoftwareMentor.com
How
Functional Programming
Made Me
a Better Developer
2
Hello!
3
4
“
The single responsibility principle states
that every module or class should have
responsibility over a single part of
the functionality provided by
the software, and that responsibility
should be entirely encapsulated by the
class.
-Wikipedia
5
“
The single responsibility principle states
that every module or class should have
responsibility over a single part of
the functionality provided by
the software, and that responsibility
should be entirely encapsulated by the
class.
-Wikipedia
6
What Happens
If You Follow SRP
to the Extreme?
7
8
9
10
11
http://blog.ploeh.dk/2014/03/10/solid-the-next-step-is-functional/
Extreme SRP and ISP
=
lots of fine grain classes
12
Objects can be thought of data
with behavior, but what if we
flipped that around?
13
14
F#
15
16
Task Snapper
○ C# application that grabs a
screenshot every so often
○ Focus on the language, not the
problem
17
18
19
20
21
22
23
Love Letter
○ 8 different kinds of cards, each with
their own rules
○ Write more idiomatic fp
○ No classes or exceptions
24
25
26
27
28
29
30
Blackjack!
○ Still modeling a card game
○ Something with easier business rules
○ Already knew the rules
31
32
33
How would you score a hand in
Blackjack?
Figure out how many Points
each Card is worth
Add the Points up
34
35
36
37
38
39
40
different outputs
the same output
A method, that when given the
same two inputs, it returns…
41
Methods that always return
output solely based on input
are known to be pure
42
Sound crazy?
Elm
React with Redux
43
44
45
46
47
48
49
50
51
52
53
Interfaces are powerful because
they enforce a contract at the code
level.
If the contract isn’t observed,
the code won’t compile!
Given this interface, what should GetById return?
Pop Quiz!
Anything that implements this interface will always
return an Employee object, right?
55
56
57
What Happened?
Interface said that an Employee
will always be returned
But sometimes, there won’t be an
Employee, so what to return?
Compiler can’t enforce that I
handle null / exceptions
58
59
60
61
62
Boundary (data in/out)
Business Rules (processing the data)
Workflow (combination of both)
Boundary
○ Databases, files, APIs
○ Typically impure
○ For easier testing of workflows,
recommend using an interface
○ Inspiration from Alistair Cockburn’s
Hexagonal Architecture
63
64
65
Business Rules
○ Bulk of the application
○ Purity is key
○ Remember SOLID when implementing
66
67
Workflows
○ Combines both Boundary and Business Rule
○ General shape is:
○ Data comes in through the boundary
○ Data is processed by the business rules
○ Data goes out through the boundary
68
69
70
71
72
73
74
75
References
F#
• F Sharp for Fun and Profit (https://fsharpforfunandprofit.com)
• The Book of F#: Breaking Free with Managed Functional Programming by Dave
Fancher
• F# Jumpstart (Pluralsight Course) by Kit Eason
Functional
• Mark Seemann’s blog: (http://blog.ploeh.dk)
• Hexagonal Architecture (post) by Alistair Cockburn
• Reid Evans YouTube
(https://www.youtube.com/channel/UCMxR2KmDlDMEsvfKOjzRNbA)
Code
• CRUDy : https://github.com/cameronpresley/CRUDy
• Optionally: https://github.com/cameronpresley/Optionally
Feedback!
76
http://blog.TheSoftwareMentor.com/F
eedback

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

OSS Java Analysis - What You Might Be Missing
OSS Java Analysis - What You Might Be MissingOSS Java Analysis - What You Might Be Missing
OSS Java Analysis - What You Might Be Missing
 
Humans by the hundred
Humans by the hundredHumans by the hundred
Humans by the hundred
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
Becoming fully buzzword compliant
Becoming fully buzzword compliantBecoming fully buzzword compliant
Becoming fully buzzword compliant
 
10 Faulty Behaviors of Code Review - Developer Summit Istanbul 2018
10 Faulty Behaviors of Code Review - Developer Summit Istanbul 201810 Faulty Behaviors of Code Review - Developer Summit Istanbul 2018
10 Faulty Behaviors of Code Review - Developer Summit Istanbul 2018
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?
 
Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and Manners
 
Defensive programming in php... by example
Defensive programming in php... by exampleDefensive programming in php... by example
Defensive programming in php... by example
 
Level Up Your Automated Tests
Level Up Your Automated TestsLevel Up Your Automated Tests
Level Up Your Automated Tests
 
Level Up Your Automated Tests
Level Up Your Automated TestsLevel Up Your Automated Tests
Level Up Your Automated Tests
 
Concurrency Errors in Java
Concurrency Errors in JavaConcurrency Errors in Java
Concurrency Errors in Java
 
WE are Doing it Wrong - Dmitry Sharkov
WE are Doing it Wrong - Dmitry SharkovWE are Doing it Wrong - Dmitry Sharkov
WE are Doing it Wrong - Dmitry Sharkov
 
iHale Milestone 1 Feedback
iHale Milestone 1 FeedbackiHale Milestone 1 Feedback
iHale Milestone 1 Feedback
 
Clean Software Design: The Practices to Make The Design Simple
Clean Software Design: The Practices to Make The Design SimpleClean Software Design: The Practices to Make The Design Simple
Clean Software Design: The Practices to Make The Design Simple
 
Sustainable Automation Frameworks by Kelsey Shannahan
Sustainable Automation Frameworks by Kelsey ShannahanSustainable Automation Frameworks by Kelsey Shannahan
Sustainable Automation Frameworks by Kelsey Shannahan
 
Unwritten Manual for Pair Programming
Unwritten Manual for Pair ProgrammingUnwritten Manual for Pair Programming
Unwritten Manual for Pair Programming
 
Behavior Driven Development - TdT@Cluj #15
Behavior Driven Development - TdT@Cluj #15Behavior Driven Development - TdT@Cluj #15
Behavior Driven Development - TdT@Cluj #15
 
Finding Defects in C#: Coverity vs. FxCop
Finding Defects in C#: Coverity vs. FxCopFinding Defects in C#: Coverity vs. FxCop
Finding Defects in C#: Coverity vs. FxCop
 
Legacycode01
Legacycode01Legacycode01
Legacycode01
 
Adopting Agile
Adopting AgileAdopting Agile
Adopting Agile
 

Semelhante a How Functional Programming Made Me a Better Developer

Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
John Choi
 

Semelhante a How Functional Programming Made Me a Better Developer (20)

Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 
TxJS 2011
TxJS 2011TxJS 2011
TxJS 2011
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
 
Secret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software SystemsSecret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software Systems
 
How Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better DeveloperHow Functional Programming Made Me A Better Developer
How Functional Programming Made Me A Better Developer
 
Continuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestContinuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software West
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Thinking Functionally
Thinking FunctionallyThinking Functionally
Thinking Functionally
 
Performance Tuning with XHProf
Performance Tuning with XHProfPerformance Tuning with XHProf
Performance Tuning with XHProf
 
Survive the Chaos - S4H151 - SAP TechED Barcelona 2017 - Lecture
Survive the Chaos - S4H151 - SAP TechED Barcelona 2017 - LectureSurvive the Chaos - S4H151 - SAP TechED Barcelona 2017 - Lecture
Survive the Chaos - S4H151 - SAP TechED Barcelona 2017 - Lecture
 
GraphQL vs. (the) REST
GraphQL vs. (the) RESTGraphQL vs. (the) REST
GraphQL vs. (the) REST
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Salesforce Flows Architecture Best Practices
Salesforce Flows Architecture Best PracticesSalesforce Flows Architecture Best Practices
Salesforce Flows Architecture Best Practices
 
Availability in a cloud native world v1.6 (Feb 2019)
Availability in a cloud native world v1.6 (Feb 2019)Availability in a cloud native world v1.6 (Feb 2019)
Availability in a cloud native world v1.6 (Feb 2019)
 
Twelve Factor - Designing for Change
Twelve Factor - Designing for ChangeTwelve Factor - Designing for Change
Twelve Factor - Designing for Change
 
Real World Java Compatibility
Real World Java CompatibilityReal World Java Compatibility
Real World Java Compatibility
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
 

Mais de Cameron Presley

Mais de Cameron Presley (8)

The Engineer's Playbook: Starting a New Role
The Engineer's Playbook: Starting a New RoleThe Engineer's Playbook: Starting a New Role
The Engineer's Playbook: Starting a New Role
 
Taking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain Modeling
 
Level Up Your Functional Programming Skills with LINQ
Level Up Your Functional Programming Skills with LINQLevel Up Your Functional Programming Skills with LINQ
Level Up Your Functional Programming Skills with LINQ
 
Functional Programming Through Construction : First Principles
Functional Programming Through Construction : First PrinciplesFunctional Programming Through Construction : First Principles
Functional Programming Through Construction : First Principles
 
Establishing a SOLID Foundation
Establishing a SOLID FoundationEstablishing a SOLID Foundation
Establishing a SOLID Foundation
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
Indy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing BlackjackIndy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing Blackjack
 
Establishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software DesignEstablishing a SOLID Foundation - An Intro to Software Design
Establishing a SOLID Foundation - An Intro to Software Design
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

How Functional Programming Made Me a Better Developer

Notas do Editor

  1. The Road Taken Learning Functional Programming (i.e. What Got Me Started Down This Path?)
  2. Some SOLID Inspiration SOLID = Mnemonic for software designed By following SOLID we tend to write more maintainable software Want to focus on S (Single Responsibility Principle)
  3. Lot of small classes with a single public method A lot of ceremony Could use ReSharper or another tool to create the boilerplate, but how about eliminate the need for it?
  4. Asking the Twitterverse for help
  5. Like most things in software development, I wasn’t the first to come to this
  6. Chose F# Familiar with .NET Comfortable with the tooling Community resources
  7. I worked on/off with functional for a year Lots of heads down, then come up for air for a bit Rinse and repeat Took three attempts for me to really “get” it
  8. First Attempt!
  9. Decided to port a C# application (Task Snapper) Grabs a screenshot every so often Idea was to focus on the language, not how to solve the problem
  10. Defined a type Attached functions to it Some of those functions threw exceptions
  11. Defined a type Attached functions to it Some of those functions threw exceptions
  12. Defined a type Attached functions to it Some of those functions threw exceptions
  13. Defined a type Attached functions to it Some of those functions threw exceptions
  14. I wrote F# But wrote OO in FP Didn’t really see the point Need to learn more about FP
  15. Look ma, no exceptions! Learned more about data modeling (making illegal states unrepresentable) Game rules a bit more complicated than expected *Spent a lot of time learning the problem and attempting a solution, not porting
  16. Modeling Data and State using Discriminated Unions
  17. Using type aliases
  18. Making new types out of existing types using records
  19. No classes, no exceptions!
  20. 3rd Attempt
  21. Making Illegal States Unrepresentable
  22. Modeling how to turn a Card into a
  23. How to add two points together
  24. Reflection * Comfortable with handling errors without exceptions Using pattern matching more effectively Working with built-in List operators Map and Reduce Starting to think about how to use these concepts in C#
  25. Learned all of this cool stuff, how does it affect my coding habits now?
  26. Code is easy to test implies code is easy to maintain The opposite may hold then, hard to test code may not be maintainable What defines easy to test code?
  27. What’s easier to test? Which method would be easier to troubleshoot?
  28. Implies there are no side effects (databases, file systems, apis, etc…) Easiest thing to test because no dependencies are needed
  29. Elm Architecture (time traveling debugger) React with Redux (reducers)
  30. Pure because 3 will always return the same value
  31. Not pure because the API could fail or give me back different values
  32. Improved LINQ Skills
  33. When working with lists of data, here’s how I’d used to do it Quickly, what am I trying to do here?
  34. Before and after The one on the left, I have to keep track of what I’m doing The one on the right, I can trust that LINQ works and I’m plugging my business rules into the correct places
  35. Designing Interfaces that don’t suck
  36. Allows us to lean on the compiler
  37. Why doesn’t this work? Options have no clue about Id, FirstName or LastName
  38. Pattern match to figure out what to do. Compiler forced us to do that! Win!
  39. How I build software
  40. Getting data into the system
  41. Getting data out of the system
  42. Learning functional was hard for me Lots of failures, but improved incrementally Made me re-evaluate how I build software Still use functional concepts in my coding Even if I’m not using a functional language