SlideShare a Scribd company logo
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

More Related Content

What's hot

What's hot (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
 

Similar to 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
 

Similar to 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
 

More from Cameron Presley

More from 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
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 

How Functional Programming Made Me a Better Developer

Editor's Notes

  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